Skip to main content

ImmutableString

Struct ImmutableString 

Source
pub struct ImmutableString<TAllocator: Allocator> { /* private fields */ }
Expand description

This struct is a smart pointer around a string. Internally keeps reference counters for both strong and weak references. Cloning the struct is therefore cheap.

Implementations§

Source§

impl<TAllocator: Allocator> ImmutableString<TAllocator>

Source

pub fn empty() -> Result<Self, ImmutableStringError>

Creates a new, empty ImmutableString.

This function allocates under the hood, since all immutable strings are backed by smart pointer.

§Errors

For details see ImmutableStringError.

Source

pub fn from_str_slice(text: &str) -> Result<Self, ImmutableStringError>

Creates a new ImmutableString out of passed string slice.

This function allocates under the hood, since all immutable strings are backed by smart pointer. It also copies the input into the output’s buffer.

§Errors

For details see ImmutableStringError.

Source

pub fn from_str_slice_and_allocator( text: &str, allocator: TAllocator, ) -> Result<Self, ImmutableStringError>

Creates a new ImmutableString out of passed string slice and allocator.

This function allocates under the hood, since all immutable strings are backed by smart pointer. It also copies the input into the output’s buffer.

§Errors

For details see ImmutableStringError.

Source

pub fn empty_with_allocator( allocator: TAllocator, ) -> Result<Self, ImmutableStringError>

Creates a new, empty ImmutableString with a given allocator.

This function allocates under the hood, since all immutable strings are backed by smart pointer.

§Errors

For details see ImmutableStringError.

Source

pub fn strong_count(&self) -> u32

Source

pub fn weak_count(&self) -> u32

Source

pub const fn as_str(&self) -> &str

Returns the underlying string.

Source

pub const fn as_c_str(&self) -> &str

Returns the underlying string as C-string.

Meaning the string has an additional 0 at the end of the buffer. In particular, the C-string returned by this method has length +1 compared to ImmutableString::as_str call.

Source

pub const fn length(&self) -> Length

The length of the string.

Source

pub fn downgrade(&self) -> WeakImmutableString<TAllocator>

Creates a new WeakImmutableString out of current.

Source

pub fn abandon(self) -> Option<WeakImmutableString<TAllocator>>

Abandons current ImmutableString.

This function returns None if the underlying strong reference counter is still positive. Otherwise it returns the final WeakImmutableString reference.

Trait Implementations§

Source§

impl<TAllocator: Allocator> AsRef<str> for ImmutableString<TAllocator>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<TAllocator: Allocator> Borrow<str> for ImmutableString<TAllocator>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<TAllocator: Allocator> Clone for ImmutableString<TAllocator>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<TAllocator: Debug + Allocator> Debug for ImmutableString<TAllocator>

Source§

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

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

impl<TAllocator: Allocator> Drop for ImmutableString<TAllocator>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<TAllocator: Allocator> Hash for ImmutableString<TAllocator>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<TAllocator: Allocator, TRight: AsRef<str>> PartialEq<TRight> for ImmutableString<TAllocator>

Source§

fn eq(&self, other: &TRight) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<TAllocator: Allocator> ReprC for ImmutableString<TAllocator>

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<TAllocator: Allocator> Eq for ImmutableString<TAllocator>

Auto Trait Implementations§

§

impl<TAllocator> Freeze for ImmutableString<TAllocator>
where TAllocator: Freeze,

§

impl<TAllocator> RefUnwindSafe for ImmutableString<TAllocator>
where TAllocator: RefUnwindSafe,

§

impl<TAllocator> Send for ImmutableString<TAllocator>

§

impl<TAllocator> Sync for ImmutableString<TAllocator>

§

impl<TAllocator> Unpin for ImmutableString<TAllocator>
where TAllocator: Unpin,

§

impl<TAllocator> UnsafeUnpin for ImmutableString<TAllocator>
where TAllocator: UnsafeUnpin,

§

impl<TAllocator> UnwindSafe for ImmutableString<TAllocator>
where TAllocator: UnwindSafe,

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

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.