Struct collections::string::String[src]

pub struct String {
    // some fields omitted
}

A growable string stored as a UTF-8 encoded buffer.

Methods

impl String

fn new() -> String

Creates a new string buffer initialized with the empty string.

fn with_capacity(capacity: uint) -> String

Creates a new string buffer with the given capacity.

unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String

Creates a new string buffer from length, capacity, and a pointer.

fn from_str(string: &str) -> String

Creates a new string buffer from the given string.

fn from_owned_str(string: String) -> String

fn from_utf8(vec: Vec<u8>) -> Result<String, Vec<u8>>

Returns the vector as a string buffer, if possible, taking care not to copy it.

Returns Err with the original vector if the vector contains invalid UTF-8.

fn into_bytes(self) -> Vec<u8>

Return the underlying byte buffer, encoded as UTF-8.

fn append(self, second: &str) -> String

Pushes the given string onto this buffer; then, returns self so that it can be used again.

fn from_char(length: uint, ch: char) -> String

Creates a string buffer by repeating a character length times.

fn push_str(&mut self, string: &str)

Pushes the given string onto this string buffer.

fn grow(&mut self, count: uint, ch: char)

Push ch onto the given string count times.

fn byte_capacity(&self) -> uint

Returns the number of bytes that this string buffer can hold without reallocating.

fn reserve_additional(&mut self, extra: uint)

Reserves capacity for at least extra additional bytes in this string buffer.

fn reserve(&mut self, capacity: uint)

Reserves capacity for at least capacity bytes in this string buffer.

fn reserve_exact(&mut self, capacity: uint)

Reserves capacity for exactly capacity bytes in this string buffer.

fn shrink_to_fit(&mut self)

Shrinks the capacity of this string buffer to match its length.

fn push_char(&mut self, ch: char)

Adds the given character to the end of the string.

unsafe fn push_bytes(&mut self, bytes: &[u8])

Pushes the given bytes onto this string buffer. This is unsafe because it does not check to ensure that the resulting string will be valid UTF-8.

fn as_bytes<'a>(&'a self) -> &'a [u8]

Works with the underlying buffer as a byte slice.

unsafe fn as_mut_bytes<'a>(&'a mut self) -> &'a mut [u8]

Works with the underlying buffer as a mutable byte slice. Unsafe because this can be used to violate the UTF-8 property.

fn truncate(&mut self, len: uint)

Shorten a string to the specified length (which must be <= the current length)

unsafe fn push_byte(&mut self, byte: u8)

Appends a byte to this string buffer. The caller must preserve the valid UTF-8 property.

unsafe fn pop_byte(&mut self) -> Option<u8>

Removes the last byte from the string buffer and returns it. Returns None if this string buffer is empty.

The caller must preserve the valid UTF-8 property.

fn pop_char(&mut self) -> Option<char>

Removes the last character from the string buffer and returns it. Returns None if this string buffer is empty.

unsafe fn shift_byte(&mut self) -> Option<u8>

Removes the first byte from the string buffer and returns it. Returns None if this string buffer is empty.

The caller must preserve the valid UTF-8 property.

fn shift_char(&mut self) -> Option<char>

Removes the first character from the string buffer and returns it. Returns None if this string buffer is empty.

Warning

This is a O(n) operation as it requires copying every element in the buffer.

unsafe fn as_mut_vec<'a>(&'a mut self) -> &'a mut Vec<u8>

Views the string buffer as a mutable sequence of bytes.

Callers must preserve the valid UTF-8 property.

Trait Implementations

impl<'a> IntoMaybeOwned<'a> for String

fn into_maybe_owned(self) -> MaybeOwned<'a>

impl OwnedStr for String

fn into_bytes(self) -> Vec<u8>

fn append(self, rhs: &str) -> String

impl Collection for String

fn len(&self) -> uint

fn is_empty(&self) -> bool

impl Mutable for String

fn clear(&mut self)

impl FromIterator<char> for String

fn from_iter<I: Iterator<char>>(iterator: I) -> String

impl Extendable<char> for String

fn extend<I: Iterator<char>>(&mut self, iterator: I)

impl Str for String

fn as_slice<'a>(&'a self) -> &'a str

impl StrAllocating for String

fn into_string(self) -> String

fn to_string(&self) -> String

fn into_owned(self) -> String

fn escape_default(&self) -> String

fn escape_unicode(&self) -> String

fn replace(&self, from: &str, to: &str) -> String

fn to_owned(&self) -> String

fn to_utf16(&self) -> Vec<u16>

fn repeat(&self, nn: uint) -> String

fn lev_distance(&self, t: &str) -> uint

fn nfd_chars<'a>(&'a self) -> Decompositions<'a>

fn nfkd_chars<'a>(&'a self) -> Decompositions<'a>

impl Default for String

fn default() -> String

impl Show for String

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

impl<H: Writer> Hash<H> for String

fn hash(&self, hasher: &mut H)

impl<'a, S: Str> Equiv<S> for String

fn equiv(&self, other: &S) -> bool

impl<S: Str> Add<S, String> for String

fn add(&self, other: &S) -> String

Derived Implementations

impl Ord for String

fn cmp(&self, __arg_0: &String) -> Ordering

impl Eq for String

impl PartialOrd for String

fn lt(&self, __arg_0: &String) -> bool

fn le(&self, __arg_0: &String) -> bool

fn gt(&self, __arg_0: &String) -> bool

fn ge(&self, __arg_0: &String) -> bool

impl PartialEq for String

fn eq(&self, __arg_0: &String) -> bool

fn ne(&self, __arg_0: &String) -> bool

impl Clone for String

fn clone(&self) -> String

fn clone_from(&mut self, source: &Self)