[−][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
.
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]
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.
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.
Safety
You must ensure that:
- The backing storage type
T
adheres to the contract as documented on theStableAsRef
marker trait. - If
T
implementsAsRef<[u8]>
and/orAsMut<[u8]>
, the byte slice returned by callingas_ref
and/oras_mut
on the provided value represents valid utf-8.
Trait Implementations
impl<T> TryFrom<T> for String<T> where
T: AsRef<[u8]> + StableAsRef,
[src]
T: AsRef<[u8]> + StableAsRef,
type Error = Utf8Error
The type returned in the event of a conversion error.
fn try_from(value: T) -> Result<Self, Self::Error>
[src]
impl<T: Eq> Eq for String<T>
[src]
impl<T> Default for String<T> where
T: Default + StableAsRef,
[src]
T: Default + StableAsRef,
impl<T: Clone> Clone for String<T>
[src]
impl<T: PartialOrd> PartialOrd<String<T>> for String<T>
[src]
fn partial_cmp(&self, other: &String<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &String<T>) -> bool
[src]
fn le(&self, other: &String<T>) -> bool
[src]
fn gt(&self, other: &String<T>) -> bool
[src]
fn ge(&self, other: &String<T>) -> bool
[src]
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: Ord> Ord for String<T>
[src]
fn cmp(&self, other: &String<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl From<String> for String<String>
[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]>,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Deref for String<T> where
T: AsRef<[u8]>,
[src]
T: AsRef<[u8]>,
impl<T: AsRef<[u8]>> Debug for String<T>
[src]
impl<T: AsRef<[u8]>> Display for String<T>
[src]
impl<T> Borrow<str> for String<T> where
T: AsRef<[u8]>,
[src]
T: AsRef<[u8]>,
Auto Trait Implementations
impl<T> Send for String<T> where
T: Send,
T: Send,
impl<T> Unpin for String<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for String<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for String<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for String<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,