Struct ascii::AsciiString
[−]
[src]
pub struct AsciiString { // some fields omitted }
A growable string stored as an ascii encoded buffer.
Methods
impl AsciiString
[src]
fn new() -> AsciiString
Creates a new ascii string buffer initialized with the empty ascii string.
Examples
let mut s = AsciiString::new();
fn with_capacity(capacity: usize) -> AsciiString
Creates a new ascii string buffer with the given capacity. The string will be able to hold
exactly capacity
bytes without reallocating. If capacity
is 0, the ascii string will not
allocate.
Examples
let mut s = AsciiString::with_capacity(10);
fn push_str(&mut self, string: &AsciiStr)
Pushes the given ascii string onto this ascii string buffer.
Examples
use std::str::FromStr; let mut s = AsciiString::from_str("foo").unwrap(); s.push_str(AsciiStr::from_str("bar").unwrap()); assert_eq!(s, AsciiStr::from_str("foobar").unwrap());
fn capacity(&self) -> usize
Returns the number of bytes that this ascii string buffer can hold without reallocating.
Examples
let s = String::with_capacity(10); assert!(s.capacity() >= 10);
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more bytes to be inserted in the given
AsciiString
. The collection may reserve more space to avoid frequent reallocations.
Panics
Panics if the new capacity overflows usize
.
Examples
let mut s = AsciiString::new(); s.reserve(10); assert!(s.capacity() >= 10);
fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional
more bytes to be inserted in the
given AsciiString
. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore
capacity can not be relied upon to be precisely minimal. Prefer reserve
if future
insertions are expected.
Panics
Panics if the new capacity overflows usize
.
Examples
let mut s = AsciiString::new(); s.reserve_exact(10); assert!(s.capacity() >= 10);
fn shrink_to_fit(&mut self)
Shrinks the capacity of this ascii string buffer to match it's length.
Examples
use std::str::FromStr; let mut s = AsciiString::from_str("foo").unwrap(); s.reserve(100); assert!(s.capacity() >= 100); s.shrink_to_fit(); assert_eq!(s.capacity(), 3);
fn push(&mut self, ch: Ascii)
Adds the given ascii character to the end of the ascii string.
Examples
let mut s = AsciiString::from_bytes("abc").unwrap(); s.push(Ascii::from('1').unwrap()); s.push(Ascii::from('2').unwrap()); s.push(Ascii::from('3').unwrap()); assert_eq!(s, "abc123");
fn truncate(&mut self, new_len: usize)
Shortens a ascii string to the specified length.
Panics
Panics if new_len
> current length.
Examples
let mut s = AsciiString::from_bytes("hello").unwrap(); s.truncate(2); assert_eq!(s, "he");
fn pop(&mut self) -> Option<Ascii>
Removes the last character from the ascii string buffer and returns it. Returns None
if
this string buffer is empty.
Examples
let mut s = AsciiString::from_bytes("foo").unwrap(); assert_eq!(s.pop().map(|c| c.as_char()), Some('o')); assert_eq!(s.pop().map(|c| c.as_char()), Some('o')); assert_eq!(s.pop().map(|c| c.as_char()), Some('f')); assert_eq!(s.pop(), None);
fn remove(&mut self, idx: usize) -> Ascii
Removed the ascii character from the string buffer at bytes position idx
and returns it.
Warning
This is an O(n) operation as it requires copying every element in the buffer.
Panics
If idx
is out of bounds this function will panic.
Examples
let mut s = AsciiString::from_bytes("foo").unwrap(); assert_eq!(s.remove(0).as_char(), 'f'); assert_eq!(s.remove(1).as_char(), 'o'); assert_eq!(s.remove(0).as_char(), 'o');
fn insert(&mut self, idx: usize, ch: Ascii)
Inserts a character into the ascii string buffer at byte position idx
.
Warning
This is an O(n) operation as it requires copying every element in the buffer.
Panics
If idx
is out of bounds this function will panic.
fn len(&self) -> usize
Returns the number of bytes in this ascii string.
Examples
let s = AsciiString::from_bytes("foo").unwrap(); assert_eq!(s.len(), 3);
fn is_empty(&self) -> bool
Returns true if the ascii string contains no bytes.
Examples
let mut s = AsciiString::new(); assert!(s.is_empty()); s.push(Ascii::from('a').unwrap()); assert!(!s.is_empty());
fn clear(&mut self)
Truncates the ascii string, returning it to 0 length.
Examples
let mut s = AsciiString::from_bytes("foo").unwrap(); s.clear(); assert!(s.is_empty());
fn from_bytes<B>(bytes: B) -> Result<AsciiString, B> where B: Into<Vec<u8>> + AsRef<[u8]>
Methods from Deref<Target=AsciiStr>
fn as_str(&self) -> &str
Converts &self
to a &str
slice.
fn to_ascii_string(&self) -> AsciiString
Copies the content of this AsciiStr
into an owned AsciiString
.
fn as_bytes(&self) -> &[u8]
Converts &self
into a byte slice.
fn len(&self) -> usize
Returns the number of bytes in this ascii string.
Examples
let s = AsciiStr::from_bytes("foo").unwrap(); assert_eq!(s.len(), 3);
fn is_empty(&self) -> bool
Returns true if the ascii string contains no bytes.
Examples
let mut empty = AsciiStr::from_bytes("").unwrap(); let mut full = AsciiStr::from_bytes("foo").unwrap(); assert!(empty.is_empty()); assert!(!full.is_empty());
Trait Implementations
impl Hash for AsciiString
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl Ord for AsciiString
[src]
fn cmp(&self, __arg_0: &AsciiString) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl PartialOrd for AsciiString
[src]
fn partial_cmp(&self, __arg_0: &AsciiString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &AsciiString) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &AsciiString) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &AsciiString) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &AsciiString) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Eq for AsciiString
[src]
impl PartialEq for AsciiString
[src]
fn eq(&self, __arg_0: &AsciiString) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &AsciiString) -> bool
This method tests for !=
.
impl Clone for AsciiString
[src]
fn clone(&self) -> AsciiString
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl FromStr for AsciiString
[src]
type Err = ()
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<AsciiString, ()>
Parses a string s
to return a value of this type. Read more
impl Deref for AsciiString
[src]
type Target = AsciiStr
The resulting type after dereferencing
fn deref<'a>(&'a self) -> &'a AsciiStr
The method called to dereference a value
impl DerefMut for AsciiString
[src]
impl Borrow<AsciiStr> for AsciiString
[src]
impl Into<Vec<u8>> for AsciiString
[src]
impl Into<String> for AsciiString
[src]
impl AsRef<AsciiStr> for AsciiString
[src]
impl Display for AsciiString
[src]
impl Debug for AsciiString
[src]
impl Default for AsciiString
[src]
fn default() -> AsciiString
Returns the "default value" for a type. Read more
impl FromIterator<Ascii> for AsciiString
[src]
fn from_iter<I: IntoIterator<Item=Ascii>>(iter: I) -> AsciiString
Creates a value from an iterator. Read more
impl<'a> FromIterator<&'a AsciiStr> for AsciiString
[src]
fn from_iter<I: IntoIterator<Item=&'a AsciiStr>>(iter: I) -> AsciiString
Creates a value from an iterator. Read more
impl Extend<Ascii> for AsciiString
[src]
fn extend<I: IntoIterator<Item=Ascii>>(&mut self, iterable: I)
Extends a collection with the contents of an iterator. Read more
impl<'a> Extend<&'a Ascii> for AsciiString
[src]
fn extend<I: IntoIterator<Item=&'a Ascii>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
impl<'a> Extend<&'a AsciiStr> for AsciiString
[src]
fn extend<I: IntoIterator<Item=&'a AsciiStr>>(&mut self, iterable: I)
Extends a collection with the contents of an iterator. Read more
impl<'a> Add<&'a AsciiStr> for AsciiString
[src]
type Output = AsciiString
The resulting type after applying the +
operator
fn add(self, other: &AsciiStr) -> AsciiString
The method for the +
operator
impl<T> Index<T> for AsciiString where AsciiStr: Index<T>
[src]
type Output = AsciiStr::Output
The returned type after indexing
fn index(&self, index: T) -> &AsciiStr::Output
The method for the indexing (Foo[Bar]
) operation
impl<T> IndexMut<T> for AsciiString where AsciiStr: IndexMut<T>
[src]
fn index_mut(&mut self, index: T) -> &mut AsciiStr::Output
The method for the indexing (Foo[Bar]
) operation
impl<'a> PartialEq<String> for AsciiString
[src]
fn eq(&self, other: &String) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &String) -> bool
This method tests for !=
.
impl<'a> PartialEq<&'a AsciiStr> for AsciiString
[src]
fn eq(&self, other: &&'a AsciiStr) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &&'a AsciiStr) -> bool
This method tests for !=
.
impl<'a> PartialEq<&'a str> for AsciiString
[src]
fn eq(&self, other: &&'a str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &&'a str) -> bool
This method tests for !=
.