Skip to main content

HybridString

Struct HybridString 

Source
#[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>

Source

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.

Source

pub fn is_dynamic(&self) -> bool

Whether the bytes live on the heap.

Source

pub fn len(&self) -> usize

The length in bytes, terminator excluded.

Source

pub fn is_empty(&self) -> bool

Whether the string is empty.

Source

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.

Source

pub unsafe fn to_string_lossy(&self) -> String

The text, with invalid UTF-8 replaced.

§Safety

As for as_bytes.

Trait Implementations§

Source§

impl<const N: usize> Default for HybridString<N>

Source§

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>

§

impl<const N: usize> RefUnwindSafe for HybridString<N>

§

impl<const N: usize> Unpin for HybridString<N>

§

impl<const N: usize> UnsafeUnpin for HybridString<N>

§

impl<const N: usize> UnwindSafe for HybridString<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.