[src]

Trait std::str::OwnedStr

pub trait OwnedStr {
    fn push_str_no_overallocate(&mut self, rhs: &str);
    fn push_str(&mut self, rhs: &str);
    fn push_char(&mut self, c: char);
    fn pop_char(&mut self) -> Option<char>;
    fn shift_char(&mut self) -> Option<char>;
    fn unshift_char(&mut self, ch: char);
    fn insert(&mut self, position: uint, substring: &str);
    fn insert_char(&mut self, position: uint, ch: char);
    fn append(self, rhs: &str) -> ~str;
    fn reserve_exact(&mut self, n: uint);
    fn reserve(&mut self, n: uint);
    fn capacity(&self) -> uint;
    fn truncate(&mut self, len: uint);
    fn into_bytes(self) -> ~[u8];
    unsafe fn set_len(&mut self, new_len: uint);
}

Methods for owned strings

Required Methods

fn push_str_no_overallocate(&mut self, rhs: &str)

Appends a string slice to the back of a string, without overallocating.

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

Appends a string slice to the back of a string

fn push_char(&mut self, c: char)

Appends a character to the back of a string

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

Remove the final character from a string and return it. Return None when the string is empty.

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

Remove the first character from a string and return it. Return None when the string is empty.

fn unshift_char(&mut self, ch: char)

Prepend a char to a string

fn insert(&mut self, position: uint, substring: &str)

Insert a new sub-string at the given position in a string, in O(n + m) time (with n and m the lengths of the string and the substring.) This fails if position is not at a character boundary.

fn insert_char(&mut self, position: uint, ch: char)

Insert a char at the given position in a string, in O(n + m) time (with n and m the lengths of the string and the substring.) This fails if position is not at a character boundary.

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

Concatenate two strings together.

fn reserve_exact(&mut self, n: uint)

Reserves capacity for exactly n bytes in the given string.

Assuming single-byte characters, the resulting string will be large enough to hold a string of length n.

If the capacity for s is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • s - A string
  • n - The number of bytes to reserve space for

fn reserve(&mut self, n: uint)

Reserves capacity for at least n bytes in the given string.

Assuming single-byte characters, the resulting string will be large enough to hold a string of length n.

This function will over-allocate in order to amortize the allocation costs in scenarios where the caller may need to repeatedly reserve additional space.

If the capacity for s is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • s - A string
  • n - The number of bytes to reserve space for

fn capacity(&self) -> uint

Returns the number of single-byte characters the string can hold without reallocating

fn truncate(&mut self, len: uint)

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

fn into_bytes(self) -> ~[u8]

Consumes the string, returning the underlying byte buffer.

The buffer does not have a null terminator.

unsafe fn set_len(&mut self, new_len: uint)

Sets the length of a string

This will explicitly set the size of the string, without actually modifying its buffers, so it is up to the caller to ensure that the string is actually the specified size.

Implementors