#[repr(C)]pub struct StringView {
pub data: *const u8,
pub len: usize,
}Expand description
Non-owning string — (pointer, length) pair, no \0 terminator.
Layout identical to nonstd::string_view in the C++ SDK. 8 bytes on x86 32-bit
(ptr 4 + len 4). Returned by componentName() via hidden pointer.
StringView does not take ownership — the producer guarantees the pointer’s
validity for the duration of use.
Fields§
§data: *const u8§len: usizeImplementations§
Source§impl StringView
impl StringView
Sourcepub fn from_static(s: &'static str) -> StringView
pub fn from_static(s: &'static str) -> StringView
Creates a StringView from a static &str.
Sourcepub unsafe fn as_str<'a>(self) -> &'a str
pub unsafe fn as_str<'a>(self) -> &'a str
Converts to &str. Safe only if the pointer is valid and UTF-8.
§Safety
The pointer must be valid and point to len bytes of valid UTF-8
for the lifetime 'a.
Sourcepub unsafe fn try_as_str<'a>(self) -> Result<&'a str, Utf8Error>
pub unsafe fn try_as_str<'a>(self) -> Result<&'a str, Utf8Error>
Converts to &str with explicit UTF-8 validation.
Preferable to as_str when the string content is untrusted or in
contexts where defensive validation is needed.
§Safety
The pointer must be valid and point to len bytes for the lifetime 'a.
§Errors
std::str::Utf8Error if the pointed-to bytes do not form valid UTF-8.
Trait Implementations§
Source§impl Clone for StringView
impl Clone for StringView
Source§fn clone(&self) -> StringView
fn clone(&self) -> StringView
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more