pub struct ArrayString<A: Array<Item = u8>> { /* fields omitted */ }
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.
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);
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);
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();
Return the capacity of the ArrayString
.
use arrayvec::ArrayString;
let string = ArrayString::<[_; 3]>::new();
assert_eq!(string.capacity(), 3);
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());
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");
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');
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");
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");
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);
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");
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');
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.
Return a string slice of the whole ArrayString
.
Performs copy-assignment from source
. Read more
The resulting type after dereferencing.
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
fn eq(&self, rhs: &Self) -> bool | [src] |
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
| 1.0.0 [src] |
This method tests for !=
.
fn eq(&self, rhs: &str) -> bool | [src] |
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
| 1.0.0 [src] |
This method tests for !=
.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
| 1.0.0 [src] |
This method tests for !=
.
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, rhs: &Self) -> bool | [src] |
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, rhs: &Self) -> bool | [src] |
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, rhs: &Self) -> bool | [src] |
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, rhs: &Self) -> bool | [src] |
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, rhs: &str) -> bool | [src] |
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, rhs: &str) -> bool | [src] |
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, rhs: &str) -> bool | [src] |
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, rhs: &str) -> bool | [src] |
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Mutably dereferences the value.
Write
appends written data to the end of the string.
Writes a [char
] into this writer, returning whether the write succeeded. Read more
Writes a slice of bytes into this writer, returning whether the write succeeded. Read more
Glue for usage of the [write!
] macro with implementors of this trait. Read more
Return an empty ArrayString
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static