pub type SmallText = ArrayString<[u8; 22]>;
Aliased Type§
struct SmallText { /* private fields */ }
Implementations
Source§impl<A> ArrayString<A>
impl<A> ArrayString<A>
Sourcepub fn new() -> ArrayString<A>
pub fn new() -> ArrayString<A>
Create a new empty ArrayString
.
Capacity is inferred from the type parameter.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 16]>::new();
string.push_str("foo");
assert_eq!(&string[..], "foo");
assert_eq!(string.capacity(), 16);
Sourcepub fn from(s: &str) -> Result<ArrayString<A>, CapacityError<&str>>
pub fn from(s: &str) -> Result<ArrayString<A>, CapacityError<&str>>
Create a new ArrayString
from a str
.
Capacity is inferred from the type parameter.
Errors if the backing array is not large enough to fit the string.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 3]>::from("foo").unwrap();
assert_eq!(&string[..], "foo");
assert_eq!(string.len(), 3);
assert_eq!(string.capacity(), 3);
Sourcepub fn from_byte_string(b: &A) -> Result<ArrayString<A>, Utf8Error>
pub fn from_byte_string(b: &A) -> Result<ArrayString<A>, Utf8Error>
Create a new ArrayString
from a byte string literal.
Errors if the byte string literal is not valid UTF-8.
use arrayvec::ArrayString;
let string = ArrayString::from_byte_string(b"hello world").unwrap();
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Return the capacity of the ArrayString
.
use arrayvec::ArrayString;
let string = ArrayString::<[_; 3]>::new();
assert_eq!(string.capacity(), 3);
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Return if the ArrayString
is completely filled.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 1]>::new();
assert!(!string.is_full());
string.push_str("A");
assert!(string.is_full());
Sourcepub fn push(&mut self, c: char)
pub fn push(&mut self, c: char)
Adds the given char to the end of the string.
Panics if the backing array is not large enough to fit the additional char.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 2]>::new();
string.push('a');
string.push('b');
assert_eq!(&string[..], "ab");
Sourcepub fn try_push(&mut self, c: char) -> Result<(), CapacityError<char>>
pub fn try_push(&mut self, c: char) -> Result<(), CapacityError<char>>
Adds the given char to the end of the string.
Returns Ok
if the push succeeds.
Errors if the backing array is not large enough to fit the additional char.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 2]>::new();
string.try_push('a').unwrap();
string.try_push('b').unwrap();
let overflow = string.try_push('c');
assert_eq!(&string[..], "ab");
assert_eq!(overflow.unwrap_err().element(), 'c');
Sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
Adds the given string slice to the end of the string.
Panics if the backing array is not large enough to fit the string.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 2]>::new();
string.push_str("a");
string.push_str("d");
assert_eq!(&string[..], "ad");
Sourcepub fn try_push_str<'a>(
&mut self,
s: &'a str,
) -> Result<(), CapacityError<&'a str>>
pub fn try_push_str<'a>( &mut self, s: &'a str, ) -> Result<(), CapacityError<&'a str>>
Adds the given string slice to the end of the string.
Returns Ok
if the push succeeds.
Errors if the backing array is not large enough to fit the string.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 2]>::new();
string.try_push_str("a").unwrap();
let overflow1 = string.try_push_str("bc");
string.try_push_str("d").unwrap();
let overflow2 = string.try_push_str("ef");
assert_eq!(&string[..], "ad");
assert_eq!(overflow1.unwrap_err().element(), "bc");
assert_eq!(overflow2.unwrap_err().element(), "ef");
Sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Removes the last character from the string and returns it.
Returns None
if this ArrayString
is empty.
use arrayvec::ArrayString;
let mut s = ArrayString::<[_; 3]>::from("foo").unwrap();
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('f'));
assert_eq!(s.pop(), None);
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shortens this ArrayString
to the specified length.
If new_len
is greater than the string’s current length, this has no
effect.
Panics if new_len
does not lie on a char
boundary.
use arrayvec::ArrayString;
let mut string = ArrayString::<[_; 6]>::from("foobar").unwrap();
string.truncate(3);
assert_eq!(&string[..], "foo");
string.truncate(4);
assert_eq!(&string[..], "foo");
Sourcepub fn remove(&mut self, idx: usize) -> char
pub fn remove(&mut self, idx: usize) -> char
Removes a char
from this ArrayString
at a byte position and returns it.
This is an O(n)
operation, as it requires copying every element in the
array.
Panics if idx
is larger than or equal to the ArrayString
’s length,
or if it does not lie on a char
boundary.
use arrayvec::ArrayString;
let mut s = ArrayString::<[_; 3]>::from("foo").unwrap();
assert_eq!(s.remove(0), 'f');
assert_eq!(s.remove(1), 'o');
assert_eq!(s.remove(0), 'o');
Trait Implementations
Source§impl<A> AsRef<str> for ArrayString<A>
impl<A> AsRef<str> for ArrayString<A>
Source§impl<A> Borrow<str> for ArrayString<A>
impl<A> Borrow<str> for ArrayString<A>
Source§impl<A> Clone for ArrayString<A>
impl<A> Clone for ArrayString<A>
Source§fn clone(&self) -> ArrayString<A>
fn clone(&self) -> ArrayString<A>
Source§fn clone_from(&mut self, rhs: &ArrayString<A>)
fn clone_from(&mut self, rhs: &ArrayString<A>)
source
. Read moreSource§impl<A> Debug for ArrayString<A>
impl<A> Debug for ArrayString<A>
Source§impl<A> Default for ArrayString<A>
impl<A> Default for ArrayString<A>
Source§fn default() -> ArrayString<A>
fn default() -> ArrayString<A>
Return an empty ArrayString
Source§impl<A> Deref for ArrayString<A>
impl<A> Deref for ArrayString<A>
Source§impl<A> DerefMut for ArrayString<A>
impl<A> DerefMut for ArrayString<A>
Source§impl<A> Display for ArrayString<A>
impl<A> Display for ArrayString<A>
Source§impl<A> FromStr for ArrayString<A>
impl<A> FromStr for ArrayString<A>
Source§type Err = CapacityError
type Err = CapacityError
Source§fn from_str(s: &str) -> Result<ArrayString<A>, <ArrayString<A> as FromStr>::Err>
fn from_str(s: &str) -> Result<ArrayString<A>, <ArrayString<A> as FromStr>::Err>
s
to return a value of this type. Read moreSource§impl<A> Hash for ArrayString<A>
impl<A> Hash for ArrayString<A>
Source§impl<A> Ord for ArrayString<A>
impl<A> Ord for ArrayString<A>
Source§fn cmp(&self, rhs: &ArrayString<A>) -> Ordering
fn cmp(&self, rhs: &ArrayString<A>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<A> PartialEq<str> for ArrayString<A>
impl<A> PartialEq<str> for ArrayString<A>
Source§impl<A> PartialEq for ArrayString<A>
impl<A> PartialEq for ArrayString<A>
Source§impl<A> PartialOrd<str> for ArrayString<A>
impl<A> PartialOrd<str> for ArrayString<A>
Source§impl<A> PartialOrd for ArrayString<A>
impl<A> PartialOrd for ArrayString<A>
Source§fn partial_cmp(&self, rhs: &ArrayString<A>) -> Option<Ordering>
fn partial_cmp(&self, rhs: &ArrayString<A>) -> Option<Ordering>
Source§fn lt(&self, rhs: &ArrayString<A>) -> bool
fn lt(&self, rhs: &ArrayString<A>) -> bool
Source§fn le(&self, rhs: &ArrayString<A>) -> bool
fn le(&self, rhs: &ArrayString<A>) -> bool
Source§fn gt(&self, rhs: &ArrayString<A>) -> bool
fn gt(&self, rhs: &ArrayString<A>) -> bool
Source§impl<A> Write for ArrayString<A>
Write
appends written data to the end of the string.
impl<A> Write for ArrayString<A>
Write
appends written data to the end of the string.