NonDeDuplicatedCStr

Type Alias NonDeDuplicatedCStr 

Source
pub type NonDeDuplicatedCStr<const N: usize> = NonDeDuplicatedFlexible<[u8; N], CStr>;
Expand description

For non-de-duplicated string slices stored in static variables.

Aliased Type§

pub struct NonDeDuplicatedCStr<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> NonDeDuplicatedCStr<N>

Source

pub const fn new(s: &CStr) -> Self

Construct a new instance.

Source

pub const fn new_from_bytes(arr: [u8; N]) -> Self

The given arr must be a well-formed C string, that is,

  • not containing any internal NUL bytes, and
  • end with a NUL byte, like b"abc\0".
Source

pub const fn new_from_str(s: &str) -> Self

The given &str must, like C string, not contain any internal NUL bytes. However, do not include the trailing NUL byte - that is added automatically.

Source

pub const fn get(&self) -> &CStr

Get a reference.

Implementation details: Since this type, and this function, is intended to be used for static variables only, speed doesn’t matter here. So, we use CStr::from_bytes_with_nul (instead of CStr::from_bytes_with_nul_unchecked).