Struct argdata::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

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

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

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

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

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

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

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

Get the value as &str.

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

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.