ros_message

Struct FieldInfo

Source
pub struct FieldInfo { /* private fields */ }
Expand description

Full description of one field in a msg or srv file.

Implementations§

Source§

impl FieldInfo

Source

pub fn new( datatype: &str, name: impl Into<String>, case: FieldCase, ) -> Result<FieldInfo>

Create a field of the provided type, name and variant.

§Errors

An error will be returned if the data type cannot be parsed, or const data is invalid.

§Examples
let field = FieldInfo::new("int16", "foo", FieldCase::Vector)?;

assert_eq!(field.name(), "foo");
assert_eq!(field.datatype(), &DataType::I16);
assert_eq!(field.case(), &FieldCase::Vector);
assert_eq!(format!("{}", field), "int16[] foo");
assert!(FieldInfo::new("bad/field/type", "foo", FieldCase::Vector).is_err());
Source

pub fn datatype(&self) -> &DataType

Returns the data type of the field.

Source

pub fn name(&self) -> &str

Returns the name of the field.

Source

pub fn case(&self) -> &FieldCase

Returns the case of the field.

Source

pub fn const_value(&self) -> Option<&Value>

Returns the stored value if a constant field.

Source

pub fn is_constant(&self) -> bool

Returns true if the field contains a constant value.

§Examples
assert!(!FieldInfo::new("int16", "foo", FieldCase::Vector)?.is_constant());
assert!(FieldInfo::new("int16", "foo", FieldCase::Const("12".into()))?.is_constant());
Source

pub fn md5_string( &self, package: &str, hashes: &HashMap<MessagePath, String>, ) -> Result<String>

Returns the representation of the data type when constructing the MD5 sum.

For built in types, it is the same as the message row, but with consistent whitespace.

For message types, the type is replaced with the message’s MD5 sum, which is passed in via the hashes argument.

The package argument should be the package that the current message is in, to resolve global paths of local message dependencies.

§Errors

An error will be returned if a message we depend upon is missing.

§Examples
let mut hashes = HashMap::new();
hashes.insert("foo/Header".try_into()?, "wrong_header".into());
hashes.insert("std_msgs/Header".try_into()?, "123".into());
hashes.insert("geometry_msgs/Position".try_into()?, "345".into());
hashes.insert("foo/Position".try_into()?, "678".into());

assert_eq!(
    FieldInfo::new("int16", "foo", FieldCase::Unit)?.md5_string("foo", &hashes)?,
    "int16 foo",
);
assert_eq!(
    FieldInfo::new("float64", "foo", FieldCase::Vector)?.md5_string("foo", &hashes)?,
    "float64[] foo",
);
assert_eq!(
    FieldInfo::new("byte", "foo", FieldCase::Array(12))?.md5_string("foo", &hashes)?,
    "byte[12] foo",
);
assert_eq!(
    FieldInfo::new("byte", "FOO", FieldCase::Const("12".into()))?.md5_string("foo", &hashes)?,
    "byte FOO=12",
);
assert_eq!(
    FieldInfo::new("Header", "foo", FieldCase::Unit)?.md5_string("foo", &hashes)?,
    "123 foo",
);
assert_eq!(
    FieldInfo::new("Position", "foo", FieldCase::Vector)?.md5_string("foo", &hashes)?,
    "678 foo",
);
assert_eq!(
    FieldInfo::new("geometry_msgs/Position", "foo", FieldCase::Array(12))?.md5_string("foo", &hashes)?,
    "345 foo",
);
assert!(
    FieldInfo::new("other_msgs/Position", "foo", FieldCase::Unit)?
        .md5_string("foo", &hashes)
        .is_err(),
);
Source

pub fn is_header(&self) -> bool

Returns true if this is a header field.

The header field is special, being a unit value of type std_msgs/Header and named header. Also in this special case, the package can be elided, even if we’re not in the same package.

If any of those requirements are not met, it is not a header field.

The field is special because ROS channel publishers are allowed to populate it with the node and publisher specific data.

§Examples
assert!(FieldInfo::new("Header", "header", FieldCase::Unit)?.is_header());
assert!(FieldInfo::new("std_msgs/Header", "header", FieldCase::Unit)?.is_header());
assert!(!FieldInfo::new("Header", "header", FieldCase::Vector)?.is_header());
assert!(!FieldInfo::new("Header", "header", FieldCase::Array(5))?.is_header());
assert!(FieldInfo::new("Header", "header", FieldCase::Const("12".into())).is_err());
assert!(!FieldInfo::new("Header", "some_field", FieldCase::Unit)?.is_header());

Trait Implementations§

Source§

impl Clone for FieldInfo

Source§

fn clone(&self) -> FieldInfo

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 FieldInfo

Source§

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

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

impl<'de> Deserialize<'de> for FieldInfo

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 FieldInfo

Source§

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

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

impl Hash for FieldInfo

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FieldInfo

Source§

fn eq(&self, other: &FieldInfo) -> 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 FieldInfo

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 Eq for FieldInfo

Source§

impl StructuralPartialEq for FieldInfo

Auto Trait Implementations§

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 u8)

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