pub struct StaticString<const N: usize, Encoding, Value> { /* private fields */ }Expand description
Statically sizes string.
Serialized static strings always have the same length regardless of the size of the actual string.
Extra space is padded with delimiters.
§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::<15, Utf8, _>::from(&value);
// Size is the capacity of the underlying array.
assert_eq!(Some(15), string.size());
assert_eq!(Some(15), StaticString::<15, Utf8, String>::size_hint());
// Buffer can be any type that implements `BufMut`.
let mut buffer = [0_u8; 15];
// Serialized data includes Byte Order Mark, delimiter, and padding.
assert_eq!(Ok(15), 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
0x00, 0x00, 0x00, 0x00, // Padding
]);
// Deserialization automatically strips the BOM, delimiter, and padding.
let output = StaticString::<15, Utf8, String>::deserialize(&mut buffer.as_slice())?;
assert_eq!(output, value);Trait Implementations§
Source§impl<Encoding, Value, const N: usize> Deserialize for StaticString<N, Encoding, Value>
impl<Encoding, Value, const N: usize> Deserialize for StaticString<N, Encoding, Value>
Source§fn deserialize<Buffer>(
buffer: &mut Buffer,
) -> Result<Self::Output, DeserializeError>
fn deserialize<Buffer>( buffer: &mut Buffer, ) -> Result<Self::Output, DeserializeError>
Deserializes an instance of
Deserialize::Output from the buffer. Read moreSource§impl<Encoding, Value, const N: usize> From<Value> for StaticString<N, Encoding, Value>
impl<Encoding, Value, const N: usize> From<Value> for StaticString<N, Encoding, Value>
Source§impl<Encoding, Value, const N: usize> Serialize for StaticString<N, Encoding, Value>
impl<Encoding, Value, const N: usize> Serialize for StaticString<N, Encoding, Value>
Source§fn serialize<Buffer>(
&self,
buffer: &mut Buffer,
) -> Result<usize, SerializeError>
fn serialize<Buffer>( &self, buffer: &mut Buffer, ) -> Result<usize, SerializeError>
Auto Trait Implementations§
impl<const N: usize, Encoding, Value> Freeze for StaticString<N, Encoding, Value>where
Value: Freeze,
impl<const N: usize, Encoding, Value> RefUnwindSafe for StaticString<N, Encoding, Value>where
Value: RefUnwindSafe,
Encoding: RefUnwindSafe,
impl<const N: usize, Encoding, Value> Send for StaticString<N, Encoding, Value>
impl<const N: usize, Encoding, Value> Sync for StaticString<N, Encoding, Value>
impl<const N: usize, Encoding, Value> Unpin for StaticString<N, Encoding, Value>
impl<const N: usize, Encoding, Value> UnsafeUnpin for StaticString<N, Encoding, Value>where
Value: UnsafeUnpin,
impl<const N: usize, Encoding, Value> UnwindSafe for StaticString<N, Encoding, Value>where
Value: UnwindSafe,
Encoding: UnwindSafe,
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