Struct ros_message::Msg
source · pub struct Msg { /* private fields */ }
Expand description
A ROS message parsed from a msg
file.
Implementations§
source§impl Msg
impl Msg
sourcepub fn new(path: MessagePath, source: &str) -> Result<Msg>
pub fn new(path: MessagePath, source: &str) -> Result<Msg>
Create a message from a passed in path and source.
§Errors
Returns an error if there is an error parsing the message source.
§Examples
let message = Msg::new(
"foo/Bar".try_into()?,
r#"# a comment that is ignored
Header header
uint32 a
byte[16] b
geometry_msgs/Point[] point
uint32 FOO=5
string SOME_TEXT=this is # some text, don't be fooled by the hash
"#,
)?;
assert_eq!(message.path(), &"foo/Bar".try_into()?);
assert_eq!(message.fields().len(), 6);
sourcepub fn constants(&self) -> HashMap<String, Value>
pub fn constants(&self) -> HashMap<String, Value>
Returns a map of all constant fields inside the message, with their values parsed.
§Examples
let message = Msg::new(
"foo/Bar".try_into()?,
r#"# a comment that is ignored
Header header
uint32 a
byte[16] b
geometry_msgs/Point[] point
uint32 FOO=5
string SOME_TEXT=this is # some text, don't be fooled by the hash
"#,
)?;
let constants = message.constants();
assert_eq!(constants.len(), 2);
assert_eq!(constants.get("FOO"), Some(&Value::U32(5)));
assert_eq!(
constants.get("SOME_TEXT"),
Some(&Value::String("this is # some text, don't be fooled by the hash".into())),
);
sourcepub fn path(&self) -> &MessagePath
pub fn path(&self) -> &MessagePath
Returns the path of the message.
sourcepub fn dependencies(&self) -> Vec<MessagePath>
pub fn dependencies(&self) -> Vec<MessagePath>
Returns a all message paths that this message directly depends upon.
They are listed in the order that they appear in in the message, and duplicates are allowed.
Indirect dependencies are not included, and if you want an exhaustive list of all dependencies, you have to manually traverse every message being depended upon.
§Examples
let message = Msg::new(
"foo/Bar".try_into()?,
r#"
Header header
geometry_msgs/Point[] point1
Point[] point2
foo/Point[] point2_but_with_global_path
foo/Baz[] baz
"#,
)?;
let dependencies = message.dependencies();
assert_eq!(dependencies, vec![
"std_msgs/Header".try_into()?,
"geometry_msgs/Point".try_into()?,
"foo/Point".try_into()?,
"foo/Point".try_into()?,
"foo/Baz".try_into()?,
]);
sourcepub fn get_md5_representation(
&self,
hashes: &HashMap<MessagePath, String>,
) -> Result<String>
pub fn get_md5_representation( &self, hashes: &HashMap<MessagePath, String>, ) -> Result<String>
Returns the full MD5 representation of the message.
This is the string that is sent to the MD5 hasher to digest.
§Errors
An error is returned if some dependency is missing in the hashes.
§Examples
let message = Msg::new(
"foo/Bar".try_into()?,
r#"# a comment that is ignored
Header header
uint32 a
byte[16] b
geometry_msgs/Point[] point
Baz baz
uint32 FOO=5
string SOME_TEXT=this is # some text, don't be fooled by the hash
"#,
)?;
let mut hashes = HashMap::new();
hashes.insert("std_msgs/Header".try_into()?, "hash1".into());
hashes.insert("geometry_msgs/Point".try_into()?, "hash2".into());
hashes.insert("foo/Baz".try_into()?, "hash3".into());
let representation = message.get_md5_representation(&hashes)?;
assert_eq!(
representation,
r#"uint32 FOO=5
string SOME_TEXT=this is # some text, don't be fooled by the hash
hash1 header
uint32 a
byte[16] b
hash2 point
hash3 baz"#);
sourcepub fn has_header(&self) -> bool
pub fn has_header(&self) -> bool
Returns true if the message has a header field.
A header field is a unit value named header
of type std_msgs/Header
.
The package can be elided in this special case, no matter the package that
the containing message is located in.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Msg
impl<'de> Deserialize<'de> for Msg
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 Msg
impl StructuralPartialEq for Msg
Auto Trait Implementations§
impl Freeze for Msg
impl RefUnwindSafe for Msg
impl Send for Msg
impl Sync for Msg
impl Unpin for Msg
impl UnwindSafe for Msg
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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