Struct arrayvec::ArrayString [−][src]
A string with a fixed capacity.
The ArrayString
is a string backed by a fixed size array. It keeps track
of its length.
The string is a contiguous value that you can store directly on the stack if needed.
Implementations
impl<A> ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
pub fn new() -> ArrayString<A>
[src]
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);
pub fn len(&self) -> usize
[src]
Return the length of the string.
pub fn is_empty(&self) -> bool
[src]
Returns whether the string is empty.
pub fn from(s: &str) -> Result<Self, CapacityError<&str>>
[src]
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);
pub fn from_byte_string(b: &A) -> Result<Self, Utf8Error>
[src]
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();
pub fn capacity(&self) -> usize
[src]
Return the capacity of the ArrayString
.
use arrayvec::ArrayString; let string = ArrayString::<[_; 3]>::new(); assert_eq!(string.capacity(), 3);
pub fn is_full(&self) -> bool
[src]
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());
pub fn push(&mut self, c: char)
[src]
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");
pub fn try_push(&mut self, c: char) -> Result<(), CapacityError<char>>
[src]
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');
pub fn push_str(&mut self, s: &str)
[src]
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");
pub fn try_push_str<'a>(
&mut self,
s: &'a str
) -> Result<(), CapacityError<&'a str>>
[src]
&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");
pub fn pop(&mut self) -> Option<char>
[src]
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);
pub fn truncate(&mut self, new_len: usize)
[src]
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");
pub fn remove(&mut self, idx: usize) -> char
[src]
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');
pub fn clear(&mut self)
[src]
Make the string empty.
pub unsafe fn set_len(&mut self, length: usize)
[src]
Set the strings’s length.
This function is unsafe
because it changes the notion of the
number of “valid” bytes in the string. Use with care.
This method uses debug assertions to check the validity of length
and may use other debug assertions.
pub fn as_str(&self) -> &str
[src]
Return a string slice of the whole ArrayString
.
Trait Implementations
impl<A> AsRef<str> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> Borrow<str> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> Clone for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn clone(&self) -> ArrayString<A>
[src]
fn clone_from(&mut self, rhs: &Self)
[src]
impl<A: Copy> Copy for ArrayString<A> where
A: Array<Item = u8> + Copy,
A::Index: Copy,
[src]
A: Array<Item = u8> + Copy,
A::Index: Copy,
impl<A> Debug for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> Default for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn default() -> ArrayString<A>
[src]
Return an empty ArrayString
impl<A> Deref for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> DerefMut for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> Display for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> Eq for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> FromStr for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
type Err = CapacityError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl<A> Hash for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn hash<H: Hasher>(&self, h: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A> Ord for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn cmp(&self, rhs: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<A> PartialEq<ArrayString<A>> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> PartialEq<ArrayString<A>> for str where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn eq(&self, rhs: &ArrayString<A>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A> PartialEq<str> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
impl<A> PartialOrd<ArrayString<A>> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
[src]
fn lt(&self, rhs: &Self) -> bool
[src]
fn le(&self, rhs: &Self) -> bool
[src]
fn gt(&self, rhs: &Self) -> bool
[src]
fn ge(&self, rhs: &Self) -> bool
[src]
impl<A> PartialOrd<ArrayString<A>> for str where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn partial_cmp(&self, rhs: &ArrayString<A>) -> Option<Ordering>
[src]
fn lt(&self, rhs: &ArrayString<A>) -> bool
[src]
fn le(&self, rhs: &ArrayString<A>) -> bool
[src]
fn gt(&self, rhs: &ArrayString<A>) -> bool
[src]
fn ge(&self, rhs: &ArrayString<A>) -> bool
[src]
impl<A> PartialOrd<str> for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
fn partial_cmp(&self, rhs: &str) -> Option<Ordering>
[src]
fn lt(&self, rhs: &str) -> bool
[src]
fn le(&self, rhs: &str) -> bool
[src]
fn gt(&self, rhs: &str) -> bool
[src]
fn ge(&self, rhs: &str) -> bool
[src]
impl<A> Write for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
Write
appends written data to the end of the string.
Auto Trait Implementations
impl<A> RefUnwindSafe for ArrayString<A> where
A: RefUnwindSafe,
<A as Array>::Index: RefUnwindSafe,
A: RefUnwindSafe,
<A as Array>::Index: RefUnwindSafe,
impl<A> Send for ArrayString<A> where
A: Send,
<A as Array>::Index: Send,
A: Send,
<A as Array>::Index: Send,
impl<A> Sync for ArrayString<A> where
A: Sync,
<A as Array>::Index: Sync,
A: Sync,
<A as Array>::Index: Sync,
impl<A> Unpin for ArrayString<A> where
A: Unpin,
<A as Array>::Index: Unpin,
A: Unpin,
<A as Array>::Index: Unpin,
impl<A> UnwindSafe for ArrayString<A> where
A: UnwindSafe,
<A as Array>::Index: UnwindSafe,
A: UnwindSafe,
<A as Array>::Index: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,