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.