Struct rustls_str

Source
#[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 rustls_str<'_>

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.

Source

pub unsafe fn to_str(&self) -> &str

Change a rustls_str back to a &str.

§Safety

The caller must ensure the rustls_str data is valid utf8

Trait Implementations§

Source§

impl Debug for rustls_str<'_>

Source§

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

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

impl Default for rustls_str<'_>

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>

Source§

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> Freeze for rustls_str<'a>

§

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