Skip to main content

DynamicString

Struct DynamicString 

Source
pub struct DynamicString<Length, Encoding, Value> { /* private fields */ }
Expand description

Dynamically sized string.

Encodes the size of the string in a preceding length field.

§Examples

use rsomeip_bytes::{DynamicString, LengthU32, Utf8, Serialize as _, Deserialize as _};

// A `DynamicString` encodes the size of the string in a preceeding length field.
let value = String::from("rsomeip");
let string = DynamicString::<LengthU32, Utf8, _>::from(&value);

// Size includes the length field, BOM, string, and delimiter.
assert_eq!(Some(15), string.size());
// Size hint only includes the length field.
assert_eq!(Some(4), DynamicString::<LengthU32, Utf8, String>::size_hint());

// Buffer can be any type that implements `BufMut`.
let mut buffer = [0_u8; 15];

// Serialized data includes Length, Byte Order Mark and Delimiter.
assert_eq!(Ok(15), string.serialize(&mut buffer.as_mut_slice()));
assert_eq!(buffer, [
        0x00_u8, 0x00, 0x00, 0x0b, // Length
        0xef, 0xbb, 0xbf, // UTF-8 BOM
        0x72, 0x73, 0x6f, 0x6d, 0x65, 0x69, 0x70, // "rsomeip"
        0x00, // Delimiter
    ]);

// Deserialization automatically strips the length, BOM, and delimiters.
let output = DynamicString::<LengthU32, Utf8, String>::deserialize(&mut buffer.as_slice())?;
assert_eq!(output, value);

Trait Implementations§

Source§

impl<Length, Encoding, Value> Deserialize for DynamicString<Length, Encoding, Value>
where Length: Length, Encoding: Encoding, Value: From<String>,

Source§

type Output = Value

Type of the deserialized data.
Source§

fn deserialize<Buffer>( buffer: &mut Buffer, ) -> Result<Self::Output, DeserializeError>
where Buffer: Buf + ?Sized,

Deserializes an instance of Deserialize::Output from the buffer. Read more
Source§

fn size_hint() -> Option<usize>

Returns the minimum size of a correctly serialized Self::Output. Read more
Source§

impl<Length, Encoding, Value> From<Value> for DynamicString<Length, Encoding, Value>
where Length: Length, Encoding: Encoding, Value: AsRef<str>,

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl<Length, Encoding, Value> Serialize for DynamicString<Length, Encoding, Value>
where Length: Length, Encoding: Encoding, Value: AsRef<str>,

Source§

fn serialize<Buffer>( &self, buffer: &mut Buffer, ) -> Result<usize, SerializeError>
where Buffer: BufMut + ?Sized,

Serializes self into the given buffer. Read more
Source§

fn size(&self) -> Option<usize>

Returns the size of self when serialized. Read more
Source§

fn to_bytes(&self) -> Result<Bytes, SerializeError>

Returns self serialized into Bytes. Read more

Auto Trait Implementations§

§

impl<Length, Encoding, Value> Freeze for DynamicString<Length, Encoding, Value>
where Value: Freeze,

§

impl<Length, Encoding, Value> RefUnwindSafe for DynamicString<Length, Encoding, Value>
where Value: RefUnwindSafe, Length: RefUnwindSafe, Encoding: RefUnwindSafe,

§

impl<Length, Encoding, Value> Send for DynamicString<Length, Encoding, Value>
where Value: Send, Length: Send, Encoding: Send,

§

impl<Length, Encoding, Value> Sync for DynamicString<Length, Encoding, Value>
where Value: Sync, Length: Sync, Encoding: Sync,

§

impl<Length, Encoding, Value> Unpin for DynamicString<Length, Encoding, Value>
where Value: Unpin, Length: Unpin, Encoding: Unpin,

§

impl<Length, Encoding, Value> UnsafeUnpin for DynamicString<Length, Encoding, Value>
where Value: UnsafeUnpin,

§

impl<Length, Encoding, Value> UnwindSafe for DynamicString<Length, Encoding, Value>
where Value: UnwindSafe, Length: UnwindSafe, Encoding: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.