#[repr(C)]pub struct NrStr {
pub ptr: *const u8,
pub len: u32,
pub _reserved: u32,
}Expand description
A UTF-8 string slice with a pointer and length.
This struct is #[repr(C)] and ABI-stable.
On 64-bit targets _reserved occupies the four bytes after len that
would otherwise be implicit padding. Producers must set it to zero.
Fields§
§ptr: *const u8§len: u32§_reserved: u32Implementations§
Source§impl NrStr
impl NrStr
Sourcepub fn new(s: &str) -> Self
pub fn new(s: &str) -> Self
Creates a borrowed ABI string view.
The returned value must not be used to access the string after s is
invalidated. Use NrStr::as_str only while the source is alive.
Sourcepub const fn from_static(s: &'static str) -> Self
pub const fn from_static(s: &'static str) -> Self
Creates a borrowed ABI view from a static string.
Sourcepub unsafe fn as_str<'a>(&self) -> Result<&'a str, NrViewError>
pub unsafe fn as_str<'a>(&self) -> Result<&'a str, NrViewError>
Reads this ABI view as UTF-8.
§Safety
For a non-empty view, ptr must be valid for reads of len bytes for
the lifetime of the returned reference. The pointed-to memory must not
be mutated while that reference exists.
Sourcepub unsafe fn as_bytes<'a>(&self) -> Result<&'a [u8], NrViewError>
pub unsafe fn as_bytes<'a>(&self) -> Result<&'a [u8], NrViewError>
Reads this ABI view’s raw bytes without validating UTF-8.
§Safety
For a non-empty view, ptr must be valid for reads of len bytes for
the lifetime of the returned reference. The pointed-to memory must not
be mutated while that reference exists.