Struct lib::ShortString64

source ·
#[repr(C, align(8))]
pub struct ShortString64 { /* private fields */ }

Implementations§

source§

impl ShortString64

source

pub const MAX_CAPACITY: usize = 23usize

source

pub fn new() -> Self

Constructs and empty ShortString64

source

pub const fn is_short(&self) -> bool

in a union with a long string, returns true if this has been upgraded

source

pub unsafe fn set_len(&mut self, len: usize)

Although not unsafe, sa the string is zeroed, you shold uphold that len is all user-initialised. This depends on the function that you are implementing with this.

SAFETY:

  • len must be less than or equal to ShortString64::MAX_CAPACITY
source

pub const fn len(&self) -> usize

Returns the length of this short string, len upholds fewer invariants on a short string, than on a long, these are

  • self.len() <= self.capacity() Note that self.capacity() is a constant
source

pub const fn capacity(&self) -> usize

Returns the capacity of this short string, this is a constant, which is equal to Self::MAX_CAPACITY

source

pub const fn remaining_capacity(&self) -> usize

source

pub fn next_ptr(&mut self) -> NonNull<u8>

Returns the next pointer where we should allocate our string. This validates Stacked Borrows, by using the write access of self.

Safety
  • the returned pointer is only writable if self.len() < self.capacity()
  • you must only write to this pointer if you know it is valid utf8
source

pub unsafe fn push_str_unchecked(&mut self, s: &str)

Safety
  • s.len() must be equal to or less than self.remaining_capacity()
source

pub fn push_str(&mut self, s: &str)

source

pub fn push(&mut self, ch: char)

source

pub fn into_long(&self, additional_capacity: usize) -> LongString

Converts this to a LongString. Where the capacity is equal to or greater than Self::MAX_CAPACITY + additional_capacity.

source

pub fn as_bytes(&self) -> &[u8]

Returns a slice of bytes that is always valid utf-8

source

pub fn as_str(&self) -> &str

interpret this string as a &str

source

pub fn get_sized_buf(&self) -> NonNull<[u8]>

Returns buf[0..len] as a NonNull<[u8]> with len len, you may cast the resulting slice to a &'self str at any time, assuming all unsafe functions are called with their preconditions satisified.

This is different from the restrictions on the method of the same name on LongString, where this is not always convertable.

source

pub fn get_sized_buf_mut(&mut self) -> NonNull<[u8]>

Returns buf[0..len] as a NonNull<[u8]> with len len, you may cast the resulting slice to a &'self str at any time, assuming all unsafe functions are called with their preconditions satisified.

This is different from the restrictions on the method of the same name on LongString, where this is not always convertable.

We need this method for this variant because the provenance of the returned slice is determined by the provenance of self. Therefore, if we used a &self, the region would be tagged with SharedReadOnly

source

pub fn as_mut_str(&mut self) -> &mut str

interpret this string as a &str

Trait Implementations§

source§

impl Clone for ShortString64

source§

fn clone(&self) -> ShortString64

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ShortString64

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for ShortString64

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for ShortString64

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.