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

Methods

impl<T> String<T>[src]

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

Get a reference to the underlying byte storage.

Examples

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.

Examples

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.

Examples

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

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.

Examples

Basic usage

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

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

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.

Safety

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

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: PartialEq> PartialEq<String<T>> for String<T>[src]

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

#[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
[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 From<String> for String<String>[src]

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

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

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

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

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

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

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]>, 
[src]

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, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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