from_slice

Function from_slice 

Source
pub fn from_slice<'de, T>(bytes: &[u8]) -> Result<T>
where T: Deserialize<'de>,
Expand description

Deserialize an instance of type T from bytes of ROSMSG data.

This conversion can fail if the passed stream of bytes does not match the structure expected by T. It can also fail if the structure contains unsupported elements.

ยงExamples

let value: String = from_slice(&[
    17, 0, 0, 0,
    13, 0, 0, 0,
    72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]).unwrap();
assert_eq!(value, "Hello, World!");

let value: (u16, u16) = from_slice(&[4, 0, 0, 0, 2, 4, 8, 16]).unwrap();
assert_eq!(value, (1026, 4104));