Struct StrValue

Source
pub struct StrValue<'d> { /* private fields */ }
Expand description

Represents a string value.

The string might or might not be zero terminated, and might or might not be valid UTF-8. The accessor functions will check these properties if needed.

Implementations§

Source§

impl<'d> StrValue<'d>

Source

pub fn from_bytes_without_nul(bytes: &'d [u8]) -> StrValue<'d>

Create a StrValue referring to raw bytes, which do not include a nul-terminator.

Source

pub fn from_bytes_with_nul(bytes: &'d [u8]) -> StrValue<'d>

Create a StrValue referring to raw bytes, which include a nul-terminator.

Panics if the last byte is not a nul-terminator.

Source

pub fn from_str(s: &'d str) -> StrValue<'d>

Create a StrValue referring to a non-zero terminated UTF-8 str.

Source

pub fn from_cstr(s: &'d CStr) -> StrValue<'d>

Create a StrValue referring to a zero-terminated C string.

Source

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

Get the raw bytes of the string, without zero terminmator.

Always works, regardless of what type of string the value refers to.

Source

pub fn as_str(&self) -> Result<&'d str, Utf8Error>

Get the value as &str.

Unless the StrValue refers to a &str, it is checked for valid UTF-8.

Source

pub fn as_cstr(&self) -> Result<&'d CStr, FromBytesWithNulError>

Get the value as (nul-terminated) C string.

This only works when the StrValue:

  • refers to a &Cstr,
  • refers to raw bytes including a nul terminator, but not containing any other nul bytes (this is checked), or
  • refers to an empty string.

Otherwise, it fails.

Note that this should always work for values resulting from properly encoded argdata, as long as the value doesn’t contain any embedded nul bytes.

Trait Implementations§

Source§

impl<'d> Clone for StrValue<'d>

Source§

fn clone(&self) -> StrValue<'d>

Returns a duplicate 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<'d> Copy for StrValue<'d>

Auto Trait Implementations§

§

impl<'d> Freeze for StrValue<'d>

§

impl<'d> RefUnwindSafe for StrValue<'d>

§

impl<'d> Send for StrValue<'d>

§

impl<'d> Sync for StrValue<'d>

§

impl<'d> Unpin for StrValue<'d>

§

impl<'d> UnwindSafe for StrValue<'d>

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