#[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 const EMPTY: StringView
pub const EMPTY: StringView
The empty view: null data, zero length. What a hidden-pointer return slot starts as, and what the server reads as “no text”.
Sourcepub const fn of(s: &str) -> StringView
pub const fn of(s: &str) -> StringView
A view of s to hand the server for the length of one call.
The view carries no lifetime, so it is the caller’s to keep s alive
while the server reads it. Every interface that takes a StringView
copies what it keeps, so the duration of the call is enough.
Sourcepub const fn from_static(s: &'static str) -> StringView
pub const fn from_static(s: &'static str) -> StringView
Creates a StringView from a static &str, which outlives any use.
Sourcepub unsafe fn to_owned_string(self) -> Option<String>
pub unsafe fn to_owned_string(self) -> Option<String>
Copies the viewed bytes into a String.
None when the view is empty, null, or not UTF-8 — the server’s answer
for “no text” and a malformed one read the same to a caller.
§Safety
A non-null data must point to len readable bytes.
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