pub struct BorrowedStr<'a> {
pub ptr: *const u8,
pub len: usize,
/* private fields */
}Expand description
A borrowed UTF-8 string with a lifetime tied to the producer’s storage.
Use this for 'static strings baked into a plug-in’s manifest (type names,
version strings). The host reads through the pointer while the producing
library is loaded; in v1 that is the process lifetime, since plug-ins are
not unloaded.
Fields§
§ptr: *const u8§len: usizeImplementations§
Source§impl<'a> BorrowedStr<'a>
impl<'a> BorrowedStr<'a>
Sourcepub const fn from_str(s: &'a str) -> Self
pub const fn from_str(s: &'a str) -> Self
Wraps a Rust string slice as a borrowed boundary string.
Sourcepub unsafe fn as_str(&self) -> &'a str
pub unsafe fn as_str(&self) -> &'a str
Converts the borrowed string back to a &str.
§Safety
The caller must ensure the producing storage is still live and the bytes are valid UTF-8.
Sourcepub unsafe fn try_as_str(&self) -> Result<&'a str, Utf8Error>
pub unsafe fn try_as_str(&self) -> Result<&'a str, Utf8Error>
Sourcepub unsafe fn to_string_lossy(&self) -> String
pub unsafe fn to_string_lossy(&self) -> String
Converts the borrowed string to an owned String, replacing invalid
UTF-8 sequences with the replacement character.
§Safety
The caller must ensure the producing storage is still live.
Trait Implementations§
Source§impl<'a> Clone for BorrowedStr<'a>
impl<'a> Clone for BorrowedStr<'a>
Source§fn clone(&self) -> BorrowedStr<'a>
fn clone(&self) -> BorrowedStr<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for BorrowedStr<'a>
Source§impl Debug for BorrowedStr<'_>
impl Debug for BorrowedStr<'_>
impl Send for BorrowedStr<'_>
SAFETY: BorrowedStr is just a pointer + length; sending it across threads
is sound as long as the underlying storage outlives the use. In v1 the
storage is process-lifetime static memory in the producing library.
impl Sync for BorrowedStr<'_>
SAFETY: see Send impl.