#[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.
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.
pub fn from_str_unchecked(s: &'static str) -> rustls_str<'static>
Sourcepub unsafe fn into_static(self) -> rustls_str<'static>
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.