Struct ArrayStr

pub struct ArrayStr<const N: usize> { /* private fields */ }

A simple array-backed string type with a fixed capacity.

This is used by Jiff in lieu of a Box<str> for supporting core-only environments without a dynamic memory allocator. For example, this is used to represent time zone abbreviations which can be relied upon to be short.

N must be less than 256 so that its length can be represented by an unsigned 8-bit integer.

An ArrayStr is guaranteed to be valid UTF-8.

Implementations

impl<const N: usize> ArrayStr<N>

const fn new(s: &str) -> Option<ArrayStr<N>>

Creates a new fixed capacity string.

If the given string exceeds N bytes, then this returns None. Similarly, if N exceeds u8::MAX, then this returns None.

const fn capacity() -> usize

Returns the capacity of this array string.

fn push_str(&mut self, s: &str) -> bool

Append the bytes given to the end of this string.

If the capacity would be exceeded, then this is a no-op and false is returned. Otherwise, all of s is written to this array string and true is returned.

const fn as_str(&self) -> &str

Returns this array string as a string slice.

Trait Implementations

impl<const N: usize> AsRef<str> for ArrayStr<N>

fn as_ref(&self) -> &str

impl<const N: usize> Clone for ArrayStr<N>

fn clone(&self) -> Self

impl<const N: usize> Copy for ArrayStr<N>

impl<const N: usize> Debug for ArrayStr<N>

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

impl<const N: usize> Deref for ArrayStr<N>

type Target = str;
fn deref(&self) -> &str

impl<const N: usize> Display for ArrayStr<N>

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

impl<const N: usize> Eq for ArrayStr<N>

impl<const N: usize> Hash for ArrayStr<N>

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

impl<const N: usize> Ord for ArrayStr<N>

fn cmp(&self, other: &Self) -> Ordering

impl<const N: usize> PartialEq for ArrayStr<N>

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

impl<const N: usize> PartialEq<&str> for ArrayStr<N>

fn eq(&self, rhs: &&str) -> bool

impl<const N: usize> PartialEq<str> for ArrayStr<N>

fn eq(&self, rhs: &str) -> bool

impl<const N: usize> PartialOrd for ArrayStr<N>

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

impl<const N: usize> PartialOrd<&str> for ArrayStr<N>

fn partial_cmp(&self, rhs: &&str) -> Option<Ordering>

impl<const N: usize> PartialOrd<str> for ArrayStr<N>

fn partial_cmp(&self, rhs: &str) -> Option<Ordering>

impl<const N: usize> StructuralPartialEq for ArrayStr<N>

impl<const N: usize> Write for ArrayStr<N>

fn write_str(&mut self, s: &str) -> Result

Auto Trait Implementations

impl<const N: usize> Freeze for ArrayStr<N> where [u8; N]: Freeze,

impl<const N: usize> RefUnwindSafe for ArrayStr<N> where [u8; N]: RefUnwindSafe,

impl<const N: usize> Send for ArrayStr<N> where [u8; N]: Send,

impl<const N: usize> Sync for ArrayStr<N> where [u8; N]: Sync,

impl<const N: usize> Unpin for ArrayStr<N> where [u8; N]: Unpin,

impl<const N: usize> UnsafeUnpin for ArrayStr<N> where [u8; N]: UnsafeUnpin,

impl<const N: usize> UnwindSafe for ArrayStr<N> where [u8; N]: UnwindSafe,

Blanket Implementations

impl<P, T> Receiver for ArrayStr<N> where P: Deref<Target = T> + ?Sized, T: ?Sized,

impl<T> Any for ArrayStr<N> where T: 'static + ?Sized,

impl<T> Borrow<T> for ArrayStr<N> where T: ?Sized,

impl<T> BorrowMut<T> for ArrayStr<N> where T: ?Sized,

impl<T> CloneToUninit for ArrayStr<N> where T: Clone,

impl<T> From<T> for ArrayStr<N>

impl<T> ToOwned for ArrayStr<N> where T: Clone,

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

impl<T, U> Into<U> for ArrayStr<N> where U: From<T>,

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

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