pub struct FieldInfo { /* private fields */ }
Expand description
Full description of one field in a msg
or srv
file.
Implementations§
Source§impl FieldInfo
impl FieldInfo
Sourcepub fn new(
datatype: &str,
name: impl Into<String>,
case: FieldCase,
) -> Result<FieldInfo>
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());
Sourcepub fn const_value(&self) -> Option<&Value>
pub fn const_value(&self) -> Option<&Value>
Returns the stored value if a constant field.
Sourcepub fn is_constant(&self) -> bool
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());
Sourcepub fn md5_string(
&self,
package: &str,
hashes: &HashMap<MessagePath, String>,
) -> Result<String>
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(),
);
Sourcepub fn is_header(&self) -> bool
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<'de> Deserialize<'de> for FieldInfo
impl<'de> Deserialize<'de> for FieldInfo
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for FieldInfo
impl StructuralPartialEq for FieldInfo
Auto Trait Implementations§
impl Freeze for FieldInfo
impl RefUnwindSafe for FieldInfo
impl Send for FieldInfo
impl Sync for FieldInfo
impl Unpin for FieldInfo
impl UnwindSafe for FieldInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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