[][src]Struct string::String

pub struct String<T = Vec<u8>> { /* fields omitted */ }

A UTF-8 encoded string with configurable byte storage.

This type differs from std::String in that it is generic over the underlying byte storage, enabling it to use Vec<[u8]>, &[u8], or third party types, such as Bytes.

Methods

impl<T> String<T>
[src]

Get a reference to the underlying byte storage.

Examples

let s = String::new();
let vec = s.get_ref();

Get a mutable reference to the underlying byte storage.

It is inadvisable to directly manipulate the byte storage. This function is unsafe as the bytes could no longer be valid UTF-8 after mutation.

Examples

let mut s = String::new();

unsafe {
    let vec = s.get_mut();
}

Unwraps this String, returning the underlying byte storage.

Examples

let s = String::new();
let vec = s.into_inner();

Creates a new String from a &str.

Use TryFrom for conversion from &[u8].

let _: String<Vec<u8>> = String::from_str("nice str");

impl String
[src]

Creates a new empty String.

Given that the String is empty, this will not allocate.

Examples

Basic usage

let s = String::new();
assert_eq!(s, "");

impl<T> String<T> where
    T: AsRef<[u8]>, 
[src]

Converts the provided value to a String without checking that the given value is valid UTF-8.

Use TryFrom for a safe conversion.

Trait Implementations

impl<T> TryFrom<T> for String<T> where
    T: AsRef<[u8]>, 
[src]

The type returned in the event of a conversion error.

Performs the conversion.

impl<T: Clone> Clone for String<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl From<String> for String<String>
[src]

Performs the conversion.

impl<'a> From<&'a str> for String<&'a str>
[src]

Performs the conversion.

impl<T: Eq> Eq for String<T>
[src]

impl<T: PartialOrd> PartialOrd<String<T>> for String<T>
[src]

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

impl<T: Default> Default for String<T>
[src]

Returns the "default value" for a type. Read more

impl<T: PartialEq> PartialEq<String<T>> for String<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Ord> Ord for String<T>
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<T: Hash> Hash for String<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: AsRef<[u8]>> Display for String<T>
[src]

Formats the value using the given formatter. Read more

impl<T: AsRef<[u8]>> Debug for String<T>
[src]

Formats the value using the given formatter. Read more

impl<T> Deref for String<T> where
    T: AsRef<[u8]>, 
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T> DerefMut for String<T> where
    T: AsRef<[u8]> + AsMut<[u8]>, 
[src]

Mutably dereferences the value.

Auto Trait Implementations

impl<T> Send for String<T> where
    T: Send

impl<T> Sync for String<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

Converts the given value to a String. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 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)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 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)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more