Struct lib::ShortString64
source · #[repr(C, align(8))]pub struct ShortString64 { /* private fields */ }Implementations§
source§impl ShortString64
impl ShortString64
pub const MAX_CAPACITY: usize = 23usize
sourcepub const fn is_short(&self) -> bool
pub const fn is_short(&self) -> bool
in a union with a long string, returns true if this has been upgraded
sourcepub unsafe fn set_len(&mut self, len: usize)
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:
lenmust be less than or equal toShortString64::MAX_CAPACITY
sourcepub const fn len(&self) -> usize
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 thatself.capacity()is a constant
sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns the capacity of this short string, this is a constant, which is equal to
Self::MAX_CAPACITY
pub const fn remaining_capacity(&self) -> usize
sourcepub fn next_ptr(&mut self) -> NonNull<u8>
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
sourcepub unsafe fn push_str_unchecked(&mut self, s: &str)
pub unsafe fn push_str_unchecked(&mut self, s: &str)
Safety
s.len()must be equal to or less thanself.remaining_capacity()
pub fn push_str(&mut self, s: &str)
pub fn push(&mut self, ch: char)
sourcepub fn into_long(&self, additional_capacity: usize) -> LongString
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.
sourcepub fn get_sized_buf(&self) -> NonNull<[u8]>
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.
sourcepub fn get_sized_buf_mut(&mut self) -> NonNull<[u8]>
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
sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
interpret this string as a &str
Trait Implementations§
source§impl Clone for ShortString64
impl Clone for ShortString64
source§fn clone(&self) -> ShortString64
fn clone(&self) -> ShortString64
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more