#[repr(C)]pub struct HybridString<const N: usize> {
pub len_dynamic: usize,
pub storage: HybridStringStorage<N>,
}Expand description
HybridString<N> — open.mp’s ABI-stable string: N bytes inline
(terminator included), or a heap pointer past that. len_dynamic holds the
length shifted left by one, and whether the string is on the heap in bit 0.
Not Copy: a heap string belongs to whoever built it and is freed through
the pointer it carries. Structs holding one travel by reference only.
Fields§
§len_dynamic: usize§storage: HybridStringStorage<N>Implementations§
Source§impl<const N: usize> HybridString<N>
impl<const N: usize> HybridString<N>
Sourcepub fn new(text: &str) -> Option<HybridString<N>>
pub fn new(text: &str) -> Option<HybridString<N>>
An inline copy of text, or None when it does not fit in N - 1
bytes. A string built here never owns heap memory, so it needs no drop.
Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Whether the bytes live on the heap.
Sourcepub unsafe fn as_bytes(&self) -> &[u8] ⓘ
pub unsafe fn as_bytes(&self) -> &[u8] ⓘ
The bytes, wherever they live.
§Safety
A heap string’s pointer must still be live — true of one the server hands over by reference, for as long as the object that holds it.
Sourcepub unsafe fn to_string_lossy(&self) -> String
pub unsafe fn to_string_lossy(&self) -> String
Trait Implementations§
Source§impl<const N: usize> Default for HybridString<N>
impl<const N: usize> Default for HybridString<N>
Source§fn default() -> HybridString<N>
fn default() -> HybridString<N>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<const N: usize> !Send for HybridString<N>
impl<const N: usize> !Sync for HybridString<N>
impl<const N: usize> Freeze for HybridString<N>where
HybridStringStorage<N>: Freeze,
impl<const N: usize> RefUnwindSafe for HybridString<N>where
HybridStringStorage<N>: RefUnwindSafe,
impl<const N: usize> Unpin for HybridString<N>where
HybridStringStorage<N>: Unpin,
impl<const N: usize> UnsafeUnpin for HybridString<N>where
HybridStringStorage<N>: UnsafeUnpin,
impl<const N: usize> UnwindSafe for HybridString<N>where
HybridStringStorage<N>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more