Struct ros_message::Msg

source ·
pub struct Msg { /* private fields */ }
Expand description

A ROS message parsed from a msg file.

Implementations§

source§

impl Msg

source

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);
source

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())),
);
source

pub fn path(&self) -> &MessagePath

Returns the path of the message.

source

pub fn fields(&self) -> &[FieldInfo]

Returns a slice of all fields.

source

pub fn source(&self) -> &str

Returns the original source.

source

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()?,
]);
source

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"#);
source

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 Clone for Msg

source§

fn clone(&self) -> Msg

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 Msg

source§

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

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

impl<'de> Deserialize<'de> for Msg

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 Msg

source§

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

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

impl Hash for Msg

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 Msg

source§

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

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 Msg

source§

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