pub struct Utf16LE;Expand description
UTF-16 Little Endian encoding for strings.
Normally, used with StaticString and DynamicString.
§Examples
use rsomeip_bytes::{StaticString, Utf16LE, Serialize as _, Deserialize as _};
// A `StaticString` can be used to always write the same amount of data regardless
// of the size of the string.
let value = String::from("rsomeip");
let string = StaticString::<18, Utf16LE, _>::from(&value);
// Buffer can be any type that implements `BufMut`.
let mut buffer = [0_u8; 18];
// Serialized data includes Byte Order Mark and Delimiter.
assert_eq!(Ok(18), string.serialize(&mut buffer.as_mut_slice()));
assert_eq!(buffer, [
0xff, 0xfe, // UTF-16LE BOM
0x72, 0, 0x73, 0, 0x6f, 0, 0x6d, 0, 0x65, 0, 0x69, 0, 0x70, 0, // "rsomeip"
0x00, 0x00 // Delimiter
]);
// Deserialization automatically strips the BOM and Delimiter.
let output = StaticString::<18, Utf16LE, String>::deserialize(&mut buffer.as_slice())?;
assert_eq!(output, value);Trait Implementations§
impl Copy for Utf16LE
Source§impl Encoding for Utf16LE
impl Encoding for Utf16LE
Source§fn serialize<Value, Buffer>(
value: Value,
buffer: &mut Buffer,
) -> Result<usize, SerializeError>
fn serialize<Value, Buffer>( value: Value, buffer: &mut Buffer, ) -> Result<usize, SerializeError>
Source§fn size<Value>(value: &Value) -> Option<usize>
fn size<Value>(value: &Value) -> Option<usize>
Returns the size of the
value when serialized. Read moreSource§fn deserialize<Buffer>(buffer: &mut Buffer) -> Result<String, DeserializeError>
fn deserialize<Buffer>(buffer: &mut Buffer) -> Result<String, DeserializeError>
impl Eq for Utf16LE
impl StructuralPartialEq for Utf16LE
Auto Trait Implementations§
impl Freeze for Utf16LE
impl RefUnwindSafe for Utf16LE
impl Send for Utf16LE
impl Sync for Utf16LE
impl Unpin for Utf16LE
impl UnsafeUnpin for Utf16LE
impl UnwindSafe for Utf16LE
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
Mutably borrows from an owned value. Read more