Enum nvim_rs::Value

source ·
pub enum Value {
    Nil,
    Boolean(bool),
    Integer(Integer),
    F32(f32),
    F64(f64),
    String(Utf8String),
    Binary(Vec<u8>),
    Array(Vec<Value>),
    Map(Vec<(Value, Value)>),
    Ext(i8, Vec<u8>),
}
Expand description

Represents any valid MessagePack value.

Variants§

§

Nil

Nil represents nil.

§

Boolean(bool)

Boolean represents true or false.

§

Integer(Integer)

Integer represents an integer.

A value of an Integer object is limited from -(2^63) upto (2^64)-1.

§Examples

use rmpv::Value;

assert_eq!(42, Value::from(42).as_i64().unwrap());
§

F32(f32)

A 32-bit floating point number.

§

F64(f64)

A 64-bit floating point number.

§

String(Utf8String)

String extending Raw type represents a UTF-8 string.

§Note

String objects may contain invalid byte sequence and the behavior of a deserializer depends on the actual implementation when it received invalid byte sequence. Deserializers should provide functionality to get the original byte array so that applications can decide how to handle the object

§

Binary(Vec<u8>)

Binary extending Raw type represents a byte array.

§

Array(Vec<Value>)

Array represents a sequence of objects.

§

Map(Vec<(Value, Value)>)

Map represents key-value pairs of objects.

§

Ext(i8, Vec<u8>)

Extended implements Extension interface: represents a tuple of type information and a byte array where type information is an integer whose meaning is defined by applications.

Implementations§

source§

impl Value

source

pub fn as_ref(&self) -> ValueRef<'_>

Converts the current owned Value to a ValueRef.

§Panics

Panics in unable to allocate memory to keep all internal structures and buffers.

§Examples
use rmpv::{Value, ValueRef};

let val = Value::Array(vec![
    Value::Nil,
    Value::from(42),
    Value::Array(vec![
        Value::String("le message".into())
    ])
]);

let expected = ValueRef::Array(vec![
   ValueRef::Nil,
   ValueRef::from(42),
   ValueRef::Array(vec![
       ValueRef::from("le message"),
   ])
]);

assert_eq!(expected, val.as_ref());
source

pub fn is_nil(&self) -> bool

Returns true if the Value is a Null. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::Nil.is_nil());
source

pub fn is_bool(&self) -> bool

Returns true if the Value is a Boolean. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::Boolean(true).is_bool());

assert!(!Value::Nil.is_bool());
source

pub fn is_i64(&self) -> bool

Returns true if the Value is convertible to an i64. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::from(42).is_i64());

assert!(!Value::from(42.0).is_i64());
source

pub fn is_u64(&self) -> bool

Returns true if the Value is convertible to an u64. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::from(42).is_u64());

assert!(!Value::F32(42.0).is_u64());
assert!(!Value::F64(42.0).is_u64());
source

pub fn is_f32(&self) -> bool

Returns true if (and only if) the Value is a f32. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::F32(42.0).is_f32());

assert!(!Value::from(42).is_f32());
assert!(!Value::F64(42.0).is_f32());
source

pub fn is_f64(&self) -> bool

Returns true if (and only if) the Value is a f64. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::F64(42.0).is_f64());

assert!(!Value::from(42).is_f64());
assert!(!Value::F32(42.0).is_f64());
source

pub fn is_number(&self) -> bool

Returns true if the Value is a Number. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::from(42).is_number());
assert!(Value::F32(42.0).is_number());
assert!(Value::F64(42.0).is_number());

assert!(!Value::Nil.is_number());
source

pub fn is_str(&self) -> bool

Returns true if the Value is a String. Returns false otherwise.

§Examples
use rmpv::Value;

assert!(Value::String("value".into()).is_str());

assert!(!Value::Nil.is_str());
source

pub fn is_bin(&self) -> bool

Returns true if the Value is a Binary. Returns false otherwise.

source

pub fn is_array(&self) -> bool

Returns true if the Value is an Array. Returns false otherwise.

source

pub fn is_map(&self) -> bool

Returns true if the Value is a Map. Returns false otherwise.

source

pub fn is_ext(&self) -> bool

Returns true if the Value is an Ext. Returns false otherwise.

source

pub fn as_bool(&self) -> Option<bool>

If the Value is a Boolean, returns the associated bool. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some(true), Value::Boolean(true).as_bool());

assert_eq!(None, Value::Nil.as_bool());
source

pub fn as_i64(&self) -> Option<i64>

If the Value is an integer, return or cast it to a i64. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some(42i64), Value::from(42).as_i64());

assert_eq!(None, Value::F64(42.0).as_i64());
source

pub fn as_u64(&self) -> Option<u64>

If the Value is an integer, return or cast it to a u64. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some(42u64), Value::from(42).as_u64());

assert_eq!(None, Value::from(-42).as_u64());
assert_eq!(None, Value::F64(42.0).as_u64());
source

pub fn as_f64(&self) -> Option<f64>

If the Value is a number, return or cast it to a f64. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some(42.0), Value::from(42).as_f64());
assert_eq!(Some(42.0), Value::F32(42.0f32).as_f64());
assert_eq!(Some(42.0), Value::F64(42.0f64).as_f64());

assert_eq!(Some(2147483647.0), Value::from(i32::max_value() as i64).as_f64());

assert_eq!(None, Value::Nil.as_f64());
source

pub fn as_str(&self) -> Option<&str>

If the Value is a String, returns the associated str. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some("le message"), Value::String("le message".into()).as_str());

assert_eq!(None, Value::Boolean(true).as_str());
source

pub fn as_slice(&self) -> Option<&[u8]>

If the Value is a Binary or a String, returns the associated slice. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some(&[1, 2, 3, 4, 5][..]), Value::Binary(vec![1, 2, 3, 4, 5]).as_slice());

assert_eq!(None, Value::Boolean(true).as_slice());
source

pub fn as_array(&self) -> Option<&Vec<Value>>

If the Value is an Array, returns the associated vector. Returns None otherwise.

§Examples
use rmpv::Value;

let val = Value::Array(vec![Value::Nil, Value::Boolean(true)]);

assert_eq!(Some(&vec![Value::Nil, Value::Boolean(true)]), val.as_array());

assert_eq!(None, Value::Nil.as_array());
source

pub fn as_map(&self) -> Option<&Vec<(Value, Value)>>

If the Value is a Map, returns the associated vector of key-value tuples. Returns None otherwise.

§Note

MessagePack represents map as a vector of key-value tuples.

§Examples
use rmpv::Value;

let val = Value::Map(vec![(Value::Nil, Value::Boolean(true))]);

assert_eq!(Some(&vec![(Value::Nil, Value::Boolean(true))]), val.as_map());

assert_eq!(None, Value::Nil.as_map());
source

pub fn as_ext(&self) -> Option<(i8, &[u8])>

If the Value is an Ext, returns the associated tuple with a ty and slice. Returns None otherwise.

§Examples
use rmpv::Value;

assert_eq!(Some((42, &[1, 2, 3, 4, 5][..])), Value::Ext(42, vec![1, 2, 3, 4, 5]).as_ext());

assert_eq!(None, Value::Boolean(true).as_ext());

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Display for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a [u8]> for Value

source§

fn from(v: &[u8]) -> Value

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for Value

source§

fn from(v: &str) -> Value

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, [u8]>> for Value

source§

fn from(v: Cow<'a, [u8]>) -> Value

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for Value

source§

fn from(v: Cow<'a, str>) -> Value

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(v: String) -> Value

Converts to this type from the input type.
source§

impl From<Value> for Box<CallError>

source§

fn from(val: Value) -> Box<CallError>

Converts to this type from the input type.
source§

impl From<Vec<(Value, Value)>> for Value

source§

fn from(v: Vec<(Value, Value)>) -> Value

Converts to this type from the input type.
source§

impl From<Vec<Value>> for Value

source§

fn from(v: Vec<Value>) -> Value

Converts to this type from the input type.
source§

impl From<Vec<u8>> for Value

source§

fn from(v: Vec<u8>) -> Value

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(v: bool) -> Value

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(v: f32) -> Value

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(v: f64) -> Value

Converts to this type from the input type.
source§

impl From<i16> for Value

source§

fn from(v: i16) -> Value

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(v: i32) -> Value

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(v: i64) -> Value

Converts to this type from the input type.
source§

impl From<i8> for Value

source§

fn from(v: i8) -> Value

Converts to this type from the input type.
source§

impl From<isize> for Value

source§

fn from(v: isize) -> Value

Converts to this type from the input type.
source§

impl From<u16> for Value

source§

fn from(v: u16) -> Value

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(v: u32) -> Value

Converts to this type from the input type.
source§

impl From<u64> for Value

source§

fn from(v: u64) -> Value

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(v: u8) -> Value

Converts to this type from the input type.
source§

impl From<usize> for Value

source§

fn from(v: usize) -> Value

Converts to this type from the input type.
source§

impl<V> FromIterator<V> for Value
where V: Into<Value>,

Note that an Iterator<Item = u8> will be collected into an Array, rather than a Binary

source§

fn from_iter<I>(iter: I) -> Value
where I: IntoIterator<Item = V>,

Creates a value from an iterator. Read more
source§

impl Index<&str> for Value

§

type Output = Value

The returned type after indexing.
source§

fn index(&self, index: &str) -> &Value

Performs the indexing (container[index]) operation. Read more
source§

impl Index<usize> for Value

§

type Output = Value

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Value

Performs the indexing (container[index]) operation. Read more
source§

impl<W> IntoVal<Value> for &Buffer<W>
where W: AsyncWrite + Send + Unpin + 'static,

source§

impl<W> IntoVal<Value> for &Tabpage<W>
where W: AsyncWrite + Send + Unpin + 'static,

source§

impl<W> IntoVal<Value> for &Window<W>
where W: AsyncWrite + Send + Unpin + 'static,

source§

impl<'a> IntoVal<Value> for &'a str

source§

impl IntoVal<Value> for (i64, i64)

source§

impl IntoVal<Value> for String

source§

impl IntoVal<Value> for Value

source§

impl IntoVal<Value> for Vec<(Value, Value)>

source§

impl IntoVal<Value> for Vec<String>

source§

impl IntoVal<Value> for Vec<Value>

source§

impl IntoVal<Value> for bool

source§

impl IntoVal<Value> for f64

source§

impl IntoVal<Value> for i64

source§

impl PartialEq for Value

source§

fn eq(&self, other: &Value) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryUnpack<()> for Value

source§

fn try_unpack(self) -> Result<(), Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<(i64, i64)> for Value

source§

fn try_unpack(self) -> Result<(i64, i64), Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<String> for Value

source§

fn try_unpack(self) -> Result<String, Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<Value> for Value

This is needed because the blanket impl TryFrom<Value> for Value uses Error = !.

source§

fn try_unpack(self) -> Result<Value, Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<Vec<(Value, Value)>> for Value

source§

fn try_unpack(self) -> Result<Vec<(Value, Value)>, Value>

Returns the value contained in self. Read more
source§

impl<T> TryUnpack<Vec<T>> for Value
where Value: TryUnpack<T> + From<T>,

The bound Value: From<T> is necessary so we can recover the values if one of the elements could not be unpacked. In practice, though, we only implement TryUnpack<T> in those cases anyways.

source§

fn try_unpack(self) -> Result<Vec<T>, Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<bool> for Value

source§

fn try_unpack(self) -> Result<bool, Value>

Returns the value contained in self. Read more
source§

impl TryUnpack<i64> for Value

source§

fn try_unpack(self) -> Result<i64, Value>

Returns the value contained in self. Read more
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V