Struct lib::LongString

source ·
#[repr(C)]
pub struct LongString { /* private fields */ }

Implementations§

source§

impl LongString

source

pub fn with_capacity(capacity: usize) -> Self

Construct a new LongString with at least capacity as the capacity. Note that this will panic in the case of an impossible allocation (e.g. capacity > isize::MAX)

source

pub fn as_str(&self) -> &str

interpret this as a &str

source

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

source

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

alias for self.as_str().as_bytes()

source

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

Returns a sized buffer representing the whole buffer of the string, can be safely written to so long as utf-8 constraints are not invalidated, and the buffer is not resized

source

pub fn get_non_null_slice( &self, index: usize, len: usize ) -> Option<NonNull<[u8]>>

source

pub unsafe fn get_non_null_unchecked(&self, index: usize) -> NonNull<u8>

get unchecked NonNull<u8> to an index in the buffer, use get_non_null for a safe version of this function

Safety
  • You must uphold index <= self.capacity()
source

pub fn get_non_null(&self, index: usize) -> Option<NonNull<u8>>

returns a pointer to the element of the buffer that is at an offset of index from the start, or None if the pointer is out of bounds

source

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

returns a pointer to the next element of the buffer that we want to allocate to, note that the pointer might not be writeable, as it could be outside of the buffer. In order to write to the pointer, ensure that len < capacity

source

pub const fn len(&self) -> usize

returns the length of this string in bytes, length upholds the following invariants, that you needn’t check

  • self.len() < self.capacity()
  • self.len() < isize::MAX (derived invariant from self.capacity() < isize::MAX)
source

pub const fn capacity(&self) -> usize

Returns the capacity of this string, that is, how many bytes it can fit before a realloc. Note that this does not mean extra bytes, but total bytes. Use remaining_capacity for that.

self.capacity() upholds the following invariants:

  • self.capacity() < isize::MAX
  • self.capacity() is the exact size of the allocated buffer
source

pub const fn buf(&self) -> &RawBuf<u8>

Gets the underyling buffer being used for this string

source

pub const fn remaining_capacity(&self) -> usize

returns the remaining capacity of this string (how many bytes we can allcoate before a realloc must occur)

source

pub fn clone_with_additional_capacity(&self, additional_capacity: usize) -> Self

clones this string, with at least additional_capacity extra space

source

pub fn realloc(&mut self, remaining_capacity: usize)

realloc to fit at least remaining_capacity more bytes

source

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

Safety
  • self.remaining_capacity()`` must be at least s.len()`
source

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

Push a str to this string, allocating if needed. Note that the current realloc schema might only allocate exactly enough extra space for s

source

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

Push a char to this string, allocating if needed. Like LongString::push_str this might only allocate enough extra space for ch, but that is very unlikely in this case.

source

pub fn free(&mut self)

free the buffer of this string, setting the len and capacity to 0

source

pub unsafe fn from_raw_parts( buf: NonNull<u8>, length: usize, capacity: usize ) -> Self

Construct a new LongString from a length, buf and capacity

Safety
  • invariants of length
    • 0 is always a valid value
    • len <= capacity
    • buf[0..len] is always a valid SharedReadWrite slice of valid u8, if the string is not borrowed, otherwise the permissions become that of the borrow
  • invariants of buf and capacity
    • The size of the allocated object starting at buf is exactly capacity bytes long
    • buf must be allocated with std::allocator::Global
source

pub fn from_str(s: &str) -> Self

Trait Implementations§

source§

impl Clone for LongString

source§

fn clone(&self) -> Self

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 LongString

source§

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

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

impl Display for LongString

source§

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

Formats the value using the given formatter. Read more

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.