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>
impl<TAllocator: Allocator> ImmutableString<TAllocator>
Sourcepub fn empty() -> Result<Self, ImmutableStringError>
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.
Sourcepub fn from_str_slice(text: &str) -> Result<Self, ImmutableStringError>
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.
Sourcepub fn from_str_slice_and_allocator(
text: &str,
allocator: TAllocator,
) -> Result<Self, ImmutableStringError>
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.
Sourcepub fn empty_with_allocator(
allocator: TAllocator,
) -> Result<Self, ImmutableStringError>
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.
pub fn strong_count(&self) -> u32
pub fn weak_count(&self) -> u32
Sourcepub const fn as_c_str(&self) -> &str
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.
Sourcepub fn downgrade(&self) -> WeakImmutableString<TAllocator>
pub fn downgrade(&self) -> WeakImmutableString<TAllocator>
Creates a new WeakImmutableString out of current.
Sourcepub fn abandon(self) -> Option<WeakImmutableString<TAllocator>>
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.