Enum ros_message::Value

source ·
pub enum Value {
Show 16 variants Bool(bool), I8(i8), I16(i16), I32(i32), I64(i64), U8(u8), U16(u16), U32(u32), U64(u64), F32(f32), F64(f64), String(String), Time(Time), Duration(Duration), Array(Vec<Value>), Message(MessageValue),
}
Expand description

Represents an arbitrary ROS message or value in it.

Variants§

§

Bool(bool)

Represents bool.

§

I8(i8)

Represents int8 or byte.

§

I16(i16)

Represents int16.

§

I32(i32)

Represents int32.

§

I64(i64)

Represents int64.

§

U8(u8)

Represents uint8 or char.

§

U16(u16)

Represents uint16.

§

U32(u32)

Represents uint32.

§

U64(u64)

Represents uint64.

§

F32(f32)

Represents float32.

§

F64(f64)

Represents float64.

§

String(String)

Represents string.

§

Time(Time)

Represents time.

§

Duration(Duration)

Represents duration.

§

Array(Vec<Value>)

Represents some_type[] or some_type[length].

For example: float32[64], geometry_msgs/Point[].

§

Message(MessageValue)

Represents an embedded message.

Implementations§

source§

impl Value

source

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

Returns the content if Value is a bool.

§Examples
assert_eq!(Value::Bool(true).as_bool(), Some(true));
assert_eq!(Value::Bool(false).as_bool(), Some(false));
assert!(Value::U32(12).as_bool().is_none());
source

pub fn as_i8(&self) -> Option<i8>

Returns the content if Value is an i8.

§Examples
assert_eq!(Value::I8(12).as_i8(), Some(12));
assert!(Value::U32(12).as_i8().is_none());
source

pub fn as_i16(&self) -> Option<i16>

Returns the content if Value is an i16.

§Examples
assert_eq!(Value::I16(12).as_i16(), Some(12));
assert!(Value::U32(12).as_i16().is_none());
source

pub fn as_i32(&self) -> Option<i32>

Returns the content if Value is an i32.

§Examples
assert_eq!(Value::I32(12).as_i32(), Some(12));
assert!(Value::U32(12).as_i32().is_none());
source

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

Returns the content if Value is an i64.

§Examples
assert_eq!(Value::I64(12).as_i64(), Some(12));
assert!(Value::U32(12).as_i64().is_none());
source

pub fn as_u8(&self) -> Option<u8>

Returns the content if Value is a u8.

§Examples
assert_eq!(Value::U8(12).as_u8(), Some(12));
assert!(Value::U32(12).as_u8().is_none());
source

pub fn as_u16(&self) -> Option<u16>

Returns the content if Value is a u16.

§Examples
assert_eq!(Value::U16(12).as_u16(), Some(12));
assert!(Value::U32(12).as_u16().is_none());
source

pub fn as_u32(&self) -> Option<u32>

Returns the content if Value is a u32.

§Examples
assert_eq!(Value::U32(12).as_u32(), Some(12));
assert!(Value::U16(12).as_u32().is_none());
source

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

Returns the content if Value is a u64.

§Examples
assert_eq!(Value::U64(12).as_u64(), Some(12));
assert!(Value::U32(12).as_u64().is_none());
source

pub fn as_f32(&self) -> Option<f32>

Returns the content if Value is an f32.

§Examples
assert_eq!(Value::F32(12.0).as_f32(), Some(12.0));
assert!(Value::U32(12).as_f32().is_none());
source

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

Returns the content if Value is an f64.

§Examples
assert_eq!(Value::F64(12.0).as_f64(), Some(12.0));
assert!(Value::U32(12).as_f64().is_none());
source

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

Returns a &str if Value is a String.

§Examples
assert_eq!(Value::String("foo".into()).as_str(), Some("foo"));
assert!(Value::U32(12).as_str().is_none());
source

pub fn try_into_string(self) -> Option<String>

Returns the content if Value is a String.

§Examples
assert_eq!(Value::String("foo".into()).try_into_string(), Some("foo".into()));
assert!(Value::U32(12).try_into_string().is_none());
source

pub fn as_time(&self) -> Option<Time>

Returns the content if Value is a Time struct.

§Examples
assert_eq!(
    Value::Time(Time::from_nanos(120)).as_time(),
    Some(Time::from_nanos(120)),
);
assert!(Value::U32(12).as_time().is_none());
source

pub fn as_duration(&self) -> Option<Duration>

Returns the content if Value is a Duration struct.

§Examples
assert_eq!(
    Value::Duration(Duration::from_nanos(120)).as_duration(),
    Some(Duration::from_nanos(120)),
);
assert!(Value::U32(12).as_duration().is_none());
source

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

Returns a reference to the content if Value is an array.

§Examples
assert_eq!(
    Value::Array(vec![1u32.into(), 2u32.into(), 3u32.into()]).as_slice(),
    Some(&[Value::U32(1), Value::U32(2), Value::U32(3)][..]),
);
assert!(Value::U32(12).as_slice().is_none());
source

pub fn try_into_vec(self) -> Option<Vec<Value>>

Returns the content if Value is an array.

§Examples
assert_eq!(
    Value::Array(vec![1u32.into(), 2u32.into(), 3u32.into()]).try_into_vec(),
    Some(vec![Value::U32(1), Value::U32(2), Value::U32(3)]),
);
assert!(Value::U32(12).try_into_vec().is_none());
source

pub fn as_map(&self) -> Option<&MessageValue>

Returns a reference to the content if Value is a message.

§Examples
let mut data = HashMap::<String, Value>::new();
data.insert("foo".into(), true.into());
data.insert("bar".into(), false.into());
assert_eq!(Value::Message(data.clone()).as_map(), Some(&data));
assert!(Value::U32(12).as_map().is_none());
source

pub fn try_into_map(self) -> Option<MessageValue>

Returns the content if Value is a message.

§Examples
let mut data = HashMap::<String, Value>::new();
data.insert("foo".into(), true.into());
data.insert("bar".into(), false.into());
assert_eq!(Value::Message(data.clone()).try_into_map(), Some(data));
assert!(Value::U32(12).try_into_map().is_none());

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

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

impl<'de> Deserialize<'de> for Value

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Value

source§

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

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

impl<T: Into<Value>, const L: usize> From<[T; L]> for Value

source§

fn from(v: [T; L]) -> Self

Converts to this type from the input type.
source§

impl From<Duration> for Value

source§

fn from(v: Duration) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<String, Value>> for Value

source§

fn from(v: HashMap<String, Value>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(v: String) -> Self

Converts to this type from the input type.
source§

impl From<Time> for Value

source§

fn from(v: Time) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Value>> From<Vec<T>> for Value

source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(v: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(v: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Value

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(v: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Value

source§

fn from(v: i8) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Value

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value

source§

fn from(v: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl<K: Into<String>, T: Into<Value>> FromIterator<(K, T)> for Value

source§

fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: Into<Value>> FromIterator<T> for Value

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq for Value

source§

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

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

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

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

impl Serialize for Value

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: TryFrom<Value>, const L: usize> TryFrom<Value> for [T; L]

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for Duration

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for HashMap<String, Value>

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for String

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for Time

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: TryFrom<Value>> TryFrom<Value> for Vec<T>

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for bool

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for f32

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for f64

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i16

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i32

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i64

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i8

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u16

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u32

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u64

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u8

source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

source§

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>,

source§

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>,

source§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,