[][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.

In order to construct String via any of the non-unsafe constructors, the backing storage needs to implement the StableAsRef marker trait. If you wish to construct String with a type that does not implement StableAsRef, you can use the from_utf8_unchecked constructor.


impl<T> String<T>[src]

pub fn get_ref(&self) -> &T[src]

Get a reference to the underlying byte storage.


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

pub unsafe fn get_mut(&mut self) -> &mut T[src]

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.


let mut s = String::new();

unsafe {
    let vec = s.get_mut();

pub fn into_inner(self) -> T[src]

Unwraps this String, returning the underlying byte storage.


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

pub fn from_str<'a>(src: &'a str) -> String<T> where
    T: From<&'a [u8]> + StableAsRef

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]

pub fn new() -> String[src]

Creates a new empty String.

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


Basic usage

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

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

pub unsafe fn from_utf8_unchecked(value: T) -> String<T>[src]

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

Use TryFrom for a safe conversion.


You must ensure that:

  1. The backing storage type T adheres to the contract as documented on the StableAsRef marker trait.
  2. If T implements AsRef<[u8]> and/or AsMut<[u8]>, the byte slice returned by calling as_ref and/or as_mut on the provided value represents valid utf-8.

Trait Implementations

impl<T> TryFrom<T> for String<T> where
    T: AsRef<[u8]> + StableAsRef

type Error = Utf8Error

The type returned in the event of a conversion error.

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

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

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

impl<T> PartialEq<str> for String<T> where
    T: AsRef<[u8]>, 

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

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

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

impl<T> Default for String<T> where
    T: Default + StableAsRef

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

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

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

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

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher

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

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

type Target = str

The resulting type after dereferencing.

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

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

impl<T> Borrow<str> for String<T> where
    T: AsRef<[u8]>, 

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 

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

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

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