Enum ros_message::DataType

source ·
pub enum DataType {
Show 16 variants Bool, I8(I8Variant), I16, I32, I64, U8(U8Variant), U16, U32, U64, F32, F64, String, Time, Duration, LocalMessage(String), GlobalMessage(MessagePath),
}
Expand description

Enumerates all data types possible in a ROS message.

Variants§

§

Bool

Represents bool.

§

I8(I8Variant)

Represents int8 or byte.

Variants are grouped to hint at the fact that they should be treated like the same type by most code. The key exception being matching messages for validating MD5 sums and message descriptors.

§

I16

Represents int16.

§

I32

Represents int32.

§

I64

Represents int64.

§

U8(U8Variant)

Represents uint8 or char.

Variants are grouped to hint at the fact that they should be treated like the same type by most code. The key exception being matching messages for validating MD5 sums and message descriptors.

§

U16

Represents uint16.

§

U32

Represents uint32.

§

U64

Represents uint64.

§

F32

Represents float32.

§

F64

Represents float64.

§

String

Represents string.

§

Time

Represents time.

§

Duration

Represents duration.

§

LocalMessage(String)

Represents messages from same package.

When a message in package foo has a field of message type foo/Bar, it can just reference the field as Bar, and would put in this variant.

§

GlobalMessage(MessagePath)

Represents messages from any package.

When a message has a field of message type foo/Bar, it can reference the field as foo/Bar, and would put in this variant.

Implementations§

source§

impl DataType

source

pub fn parse(datatype: &str) -> Result<Self>

Parses the data type from the type provided in a ROS msg.

§Examples
assert_eq!(DataType::parse("int16")?, DataType::I16);
assert_eq!(DataType::parse("float64")?, DataType::F64);
assert_eq!(DataType::parse("byte")?, DataType::I8(I8Variant::Byte));
assert_eq!(
    DataType::parse("Header")?,
    DataType::GlobalMessage("std_msgs/Header".try_into()?),
);
assert_eq!(
    DataType::parse("Position")?,
    DataType::LocalMessage("Position".into()),
);
assert_eq!(
    DataType::parse("geometry_msgs/Position")?,
    DataType::GlobalMessage("geometry_msgs/Position".try_into()?),
);
assert!(DataType::parse("00bad_package/Name").is_err());
assert!(DataType::parse("a/bad/type").is_err());
source

pub fn is_builtin(&self) -> bool

Returns true if the type is a built in type, rather than another message.

§Examples
assert!(DataType::parse("int16")?.is_builtin());
assert!(DataType::parse("float64")?.is_builtin());
assert!(DataType::parse("byte")?.is_builtin());
assert!(!DataType::parse("Header")?.is_builtin());
assert!(!DataType::parse("Position")?.is_builtin());
assert!(!DataType::parse("geometry_msgs/Position")?.is_builtin());
source

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

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

For built in types, it is the same as the data type name.

For message types, it is that 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!(DataType::parse("int16")?.md5_str("foo", &hashes)?, "int16");
assert_eq!(DataType::parse("float64")?.md5_str("foo", &hashes)?, "float64");
assert_eq!(DataType::parse("byte")?.md5_str("foo", &hashes)?, "byte");
assert_eq!(DataType::parse("Header")?.md5_str("foo", &hashes)?, "123");
assert_eq!(DataType::parse("Position")?.md5_str("foo", &hashes)?, "678");
assert_eq!(DataType::parse("geometry_msgs/Position")?.md5_str("foo", &hashes)?, "345");
assert!(DataType::parse("other_msgs/Position")?.md5_str("foo", &hashes).is_err());

Trait Implementations§

source§

impl Clone for DataType

source§

fn clone(&self) -> DataType

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 DataType

source§

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

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

impl<'de> Deserialize<'de> for DataType

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 DataType

source§

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

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

impl From<DataType> for String

source§

fn from(src: DataType) -> String

Converts to this type from the input type.
source§

impl Hash for DataType

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 DataType

source§

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

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 TryFrom<&str> for DataType

source§

type Error = Error

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

fn try_from(src: &str) -> Result<Self>

Performs the conversion.
source§

impl Eq for DataType

source§

impl StructuralPartialEq for DataType

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