pub struct Utf8;Expand description
UTF-8 encoding for strings.
Normally, used with StaticString and DynamicString.
§Examples
use rsomeip_bytes::{StaticString, Utf8, 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::<11, Utf8, _>::from(&value);
// Buffer can be any type that implements `BufMut`.
let mut buffer = [0_u8; 11];
// Serialized data includes Byte Order Mark and Delimiter.
assert_eq!(Ok(11), string.serialize(&mut buffer.as_mut_slice()));
assert_eq!(buffer, [
0xef_u8, 0xbb, 0xbf, // UTF-8 BOM
0x72, 0x73, 0x6f, 0x6d, 0x65, 0x69, 0x70, // "rsomeip"
0x00, // Delimiter
]);
// Deserialization automatically strips the BOM and Delimiter.
let output = StaticString::<11, Utf8, String>::deserialize(&mut buffer.as_slice())?;
assert_eq!(output, value);Trait Implementations§
impl Copy for Utf8
Source§impl Encoding for Utf8
impl Encoding for Utf8
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 Utf8
impl StructuralPartialEq for Utf8
Auto Trait Implementations§
impl Freeze for Utf8
impl RefUnwindSafe for Utf8
impl Send for Utf8
impl Sync for Utf8
impl Unpin for Utf8
impl UnsafeUnpin for Utf8
impl UnwindSafe for Utf8
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