#[repr(C)]
pub struct rustls_str<'a> { pub data: *const c_char, pub len: size_t, /* private fields */ }
Expand description

A read-only view on a Rust &str. The contents are guaranteed to be valid UTF-8. As an additional guarantee on top of Rust’s normal UTF-8 guarantee, a rustls_str is guaranteed not to contain internal NUL bytes, so it is safe to interpolate into a C string or compare using strncmp. Keep in mind that it is not NUL-terminated.

The memory exposed is available as specified by the function using this in its signature. For instance, when this is a parameter to a callback, the lifetime will usually be the duration of the callback. Functions that receive one of these must not dereference the data pointer beyond the allowed lifetime.

Fields§

§data: *const c_char§len: size_t

Implementations§

source§

impl<'a> rustls_str<'a>

rustls_str represents a string that can be passed to C code. The string should not have any internal NUL bytes and is not NUL terminated. C code should not create rustls_str objects, they should only be created in Rust code.

source

pub fn from_str_unchecked(s: &'static str) -> rustls_str<'static>

source

pub unsafe fn into_static(self) -> rustls_str<'static>

Change a rustls_str’s lifetime to ’static. This doesn’t actually change how long the pointed-to data lives, but is necessary when returning a rustls_str (as opposed to passing it into a callback), because Rust can’t figure out the “real” lifetime.

Safety

The caller is responsible for requiring (usually via documentation) that nothing uses the resulting rustls_str past its actual validity period. The validity period is somewhat ill-defined at present, but the Stacked Borrows experiment provides one definition, by which a shared reference is valid until a mutable reference (to the object or a parent object) is created.

Trait Implementations§

source§

impl<'a> Debug for rustls_str<'a>

source§

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

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

impl<'a> Default for rustls_str<'a>

source§

fn default() -> rustls_str<'static>

Returns the “default value” for a type. Read more
source§

impl<'a> TryFrom<&'a str> for rustls_str<'a>

§

type Error = NulByte

The type returned in the event of a conversion error.
source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for rustls_str<'a>

§

impl<'a> !Send for rustls_str<'a>

§

impl<'a> !Sync for rustls_str<'a>

§

impl<'a> Unpin for rustls_str<'a>

§

impl<'a> UnwindSafe for rustls_str<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.