Skip to main content

PaddedString

Struct PaddedString 

Source
pub struct PaddedString<const SIZE: usize> { /* private fields */ }
Expand description

Fixed-size, optionally NULL-terminated UTF-8 string read from the observer memory map.

The backing buffer is always SIZE bytes wide. Logical string content runs from byte 0 up to (but excluding) the first 0x00 byte, or to the end of the buffer if no NUL byte is present.

PaddedString has alignment 1, so it can safely be borrowed by reference even when nested inside a #[repr(C, packed)] struct.

Implementations§

Source§

impl<const SIZE: usize> PaddedString<SIZE>

Source

pub fn as_bytes(&self) -> &[u8]

Returns the bytes up to (but excluding) the first NUL byte.

If the buffer contains no NUL byte, all SIZE bytes are returned.

Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Lossy UTF-8 view of Self::as_bytes.

Invalid UTF-8 sequences are replaced with U+FFFD.

Source

pub fn len(&self) -> usize

Number of logical bytes in the string — the position of the first NULL byte, or SIZE if the buffer is not NULL-terminated.

Source

pub fn is_empty(&self) -> bool

Returns true if the first byte is NUL (i.e. the logical length is 0).

Trait Implementations§

Source§

impl<const SIZE: usize> AsRef<[u8]> for PaddedString<SIZE>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const SIZE: usize> Clone for PaddedString<SIZE>

Source§

fn clone(&self) -> PaddedString<SIZE>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const SIZE: usize> Debug for PaddedString<SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const SIZE: usize> Display for PaddedString<SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const SIZE: usize> Hash for PaddedString<SIZE>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const SIZE: usize> PartialEq for PaddedString<SIZE>

Source§

fn eq(&self, other: &PaddedString<SIZE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const SIZE: usize> Copy for PaddedString<SIZE>

Source§

impl<const SIZE: usize> Eq for PaddedString<SIZE>

Source§

impl<const SIZE: usize> StructuralPartialEq for PaddedString<SIZE>

Auto Trait Implementations§

§

impl<const SIZE: usize> Freeze for PaddedString<SIZE>

§

impl<const SIZE: usize> RefUnwindSafe for PaddedString<SIZE>

§

impl<const SIZE: usize> Send for PaddedString<SIZE>

§

impl<const SIZE: usize> Sync for PaddedString<SIZE>

§

impl<const SIZE: usize> Unpin for PaddedString<SIZE>

§

impl<const SIZE: usize> UnsafeUnpin for PaddedString<SIZE>

§

impl<const SIZE: usize> UnwindSafe for PaddedString<SIZE>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.