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
impl DataType
sourcepub fn parse(datatype: &str) -> Result<Self>
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());
sourcepub fn is_builtin(&self) -> bool
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());
sourcepub fn md5_str<'a>(
&self,
package: &str,
hashes: &'a HashMap<MessagePath, String>,
) -> Result<&'a str>
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<'de> Deserialize<'de> for DataType
impl<'de> Deserialize<'de> for DataType
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 DataType
impl StructuralPartialEq for DataType
Auto Trait Implementations§
impl Freeze for DataType
impl RefUnwindSafe for DataType
impl Send for DataType
impl Sync for DataType
impl Unpin for DataType
impl UnwindSafe for DataType
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