serde_yml::libyml::safe_cstr

Struct CStr

Source
pub struct CStr<'a> { /* private fields */ }
Expand description

Struct representing a C string.

Implementations§

Source§

impl<'a> CStr<'a>

Source

pub fn from_bytes_with_nul(bytes: &'static [u8]) -> Result<Self, CStrError>

Creates a new CStr instance from a static byte slice that is null-terminated.

§Arguments
  • bytes - A static byte slice that must be null-terminated.
§Returns

A new CStr instance representing the input byte slice.

§Errors

This method will return a CStrError if the input bytes slice does not have a null terminator.

Source

pub fn from_ptr(ptr: NonNull<i8>) -> Self

Creates a new CStr instance from a NonNull<i8> raw pointer.

§Arguments
  • ptr - A NonNull<i8> raw pointer to the null-terminated C-style string.
§Returns

A new CStr instance representing the input pointer.

Source

pub fn len(self) -> usize

Calculates the length of the C-style string represented by the CStr instance.

§Returns

The length of the C-style string, not including the null terminator.

Source

pub fn is_empty(self) -> bool

Checks if the C-style string represented by the CStr instance is empty.

§Returns

true if the C-style string is empty, false otherwise.

Source

pub fn to_bytes(self) -> &'a [u8]

Retrieves a reference to the underlying byte slice of the CStr instance.

§Returns

A borrowed reference to the byte slice represented by the CStr instance.

Trait Implementations§

Source§

impl<'a> Clone for CStr<'a>

Source§

fn clone(&self) -> CStr<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CStr<'_>

Source§

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

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

impl Display for CStr<'_>

Source§

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

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

impl<'a> Copy for CStr<'a>

Source§

impl Send for CStr<'_>

Source§

impl Sync for CStr<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for CStr<'a>

§

impl<'a> RefUnwindSafe for CStr<'a>

§

impl<'a> Unpin for CStr<'a>

§

impl<'a> UnwindSafe for CStr<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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§

default 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.