[−][src]Struct string::String
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][−]
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]>,
[src][−]
T: From<&'a [u8]>,
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][−]
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.
Trait Implementations
impl<T> TryFrom<T> for String<T> where
T: AsRef<[u8]>,
[src][+]
T: AsRef<[u8]>,
impl<T: PartialEq> PartialEq<String<T>> for String<T>
[src][+]
impl<T> PartialEq<str> for String<T> where
T: AsRef<[u8]>,
[src][+]
T: AsRef<[u8]>,
impl<T: Default> Default for String<T>
[src][+]
impl<T: Ord> Ord for String<T>
[src][+]
impl<T: Clone> Clone for String<T>
[src][+]
impl From<String> for String<String>
[src][+]
impl<'a> From<&'a str> for String<&'a str>
[src][+]
impl<T: Eq> Eq for String<T>
[src]
impl<T: PartialOrd> PartialOrd<String<T>> for String<T>
[src][+]
impl<T: AsRef<[u8]>> Debug for String<T>
[src][+]
impl<T: AsRef<[u8]>> Display for String<T>
[src][+]
impl<T> DerefMut for String<T> where
T: AsRef<[u8]> + AsMut<[u8]>,
[src][+]
T: AsRef<[u8]> + AsMut<[u8]>,
impl<T> Hash for String<T> where
T: AsRef<[u8]>,
[src][+]
T: AsRef<[u8]>,
impl<T> Deref for String<T> where
T: AsRef<[u8]>,
[src][+]
T: AsRef<[u8]>,
impl<T> Borrow<str> for String<T> where
T: AsRef<[u8]>,
[src][+]
T: AsRef<[u8]>,
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src][−]
T: Display + ?Sized,
impl<T> From for T
[src][−]
impl<T, U> Into for T where
U: From<T>,
[src][−]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][−]
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src][−]
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src][−]
impl<T> Borrow for T where
T: ?Sized,
[src][−]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src][−]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src][−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src][−]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src][−]
impl<T> Any for T where
T: 'static + ?Sized,
[src][−]
T: 'static + ?Sized,