Struct ByteString

#[repr(transparent)]
pub struct ByteString(pub Vec<u8>);

A wrapper for Vec<u8> representing a human-readable string that's conventionally, but not always, UTF-8.

Unlike String, this type permits non-UTF-8 contents, making it suitable for user input, non-native filenames (as Path only supports native filenames), and other applications that need to round-trip whatever data the user provides.

A ByteString owns its contents and can grow and shrink, like a Vec or String. For a borrowed byte string, see ByteStr.

ByteString implements Deref to &Vec<u8>, so all methods available on &Vec<u8> are available on ByteString. Similarly, ByteString implements DerefMut to &mut Vec<u8>, so you can modify a ByteString using any method available on &mut Vec<u8>.

The Debug and Display implementations for ByteString are the same as those for ByteStr, showing invalid UTF-8 as hex escapes or the Unicode replacement character, respectively.

Fields

0: Vec<u8>

Implementations

impl ByteString

fn as_bytes(&self) -> &[u8]
fn as_bytestr(&self) -> &ByteStr
fn as_mut_bytestr(&mut self) -> &mut ByteStr
fn to_string(&self) -> Result<String, Utf8Error>

Try to get a String representation of the &ByteString, if it is valid UTF-8.

This method is named to_string() because we want ByteString to implement Display, but the ToString trait has a blanket implementation for types that implement Display, and the trait version will use the Unicode replacement character rather than returning a Result and allowing for the possibility of the content not being UTF-8.

Trait Implementations

impl AsMut<ByteStr> for ByteString

fn as_mut(&mut self) -> &mut ByteStr

impl AsMut<[u8]> for ByteString

fn as_mut(&mut self) -> &mut [u8]

impl AsRef<ByteStr> for ByteString

fn as_ref(&self) -> &ByteStr

impl AsRef<[u8]> for ByteString

fn as_ref(&self) -> &[u8]

impl Borrow<ByteStr> for ByteString

fn borrow(&self) -> &ByteStr

impl Borrow<[u8]> for ByteString

fn borrow(&self) -> &[u8]

impl BorrowMut<ByteStr> for ByteString

fn borrow_mut(&mut self) -> &mut ByteStr

impl BorrowMut<[u8]> for ByteString

fn borrow_mut(&mut self) -> &mut [u8]

impl Clone for ByteString

fn clone(&self) -> ByteString

impl Debug for ByteString

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Default for ByteString

fn default() -> Self

impl Deref for ByteString

type Target = Vec<u8>;
fn deref(&self) -> &Self::Target

impl DerefMut for ByteString

fn deref_mut(&mut self) -> &mut Self::Target

impl DerefPure for ByteString

impl Display for ByteString

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for ByteString

impl FromIterator<ByteString> for ByteString

fn from_iter<T: IntoIterator<Item = ByteString>>(iter: T) -> Self

impl FromIterator<char> for ByteString

fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self

impl FromIterator<u8> for ByteString

fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self

impl FromStr for ByteString

type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err>

impl Hash for ByteString

fn hash<H: Hasher>(&self, state: &mut H)

impl Index<Range<usize>> for ByteString

type Output = ByteStr;
fn index(&self, r: Range<usize>) -> &ByteStr

impl Index<RangeFrom<usize>> for ByteString

type Output = ByteStr;
fn index(&self, r: RangeFrom<usize>) -> &ByteStr

impl Index<RangeFull> for ByteString

type Output = ByteStr;
fn index(&self, RangeFull) -> &ByteStr

impl Index<RangeInclusive<usize>> for ByteString

type Output = ByteStr;
fn index(&self, r: RangeInclusive<usize>) -> &ByteStr

impl Index<RangeTo<usize>> for ByteString

type Output = ByteStr;
fn index(&self, r: RangeTo<usize>) -> &ByteStr

impl Index<RangeToInclusive<usize>> for ByteString

type Output = ByteStr;
fn index(&self, r: RangeToInclusive<usize>) -> &ByteStr

impl Index<usize> for ByteString

type Output = u8;
fn index(&self, idx: usize) -> &u8

impl IndexMut<Range<usize>> for ByteString

fn index_mut(&mut self, r: Range<usize>) -> &mut ByteStr

impl IndexMut<RangeFrom<usize>> for ByteString

fn index_mut(&mut self, r: RangeFrom<usize>) -> &mut ByteStr

impl IndexMut<RangeFull> for ByteString

fn index_mut(&mut self, RangeFull) -> &mut ByteStr

impl IndexMut<RangeInclusive<usize>> for ByteString

fn index_mut(&mut self, r: RangeInclusive<usize>) -> &mut ByteStr

impl IndexMut<RangeTo<usize>> for ByteString

fn index_mut(&mut self, r: RangeTo<usize>) -> &mut ByteStr

impl IndexMut<RangeToInclusive<usize>> for ByteString

fn index_mut(&mut self, r: RangeToInclusive<usize>) -> &mut ByteStr

impl IndexMut<usize> for ByteString

fn index_mut(&mut self, idx: usize) -> &mut u8

impl Ord for ByteString

fn cmp(&self, other: &ByteString) -> Ordering

impl PartialEq for ByteString

fn eq(&self, other: &ByteString) -> bool

impl PartialEq<&ByteStr> for ByteString

fn eq(&self, other: &&ByteStr) -> bool

impl PartialEq<&[u8]> for ByteString

fn eq(&self, other: &&[u8]) -> bool

impl PartialEq<&str> for ByteString

fn eq(&self, other: &&str) -> bool

impl PartialEq<ByteStr> for ByteString

fn eq(&self, other: &ByteStr) -> bool

impl PartialEq<Cow<'_, ByteStr>> for ByteString

fn eq(&self, other: &Cow<'_, ByteStr>) -> bool

impl PartialEq<Cow<'_, [u8]>> for ByteString

fn eq(&self, other: &Cow<'_, [u8]>) -> bool

impl PartialEq<Cow<'_, str>> for ByteString

fn eq(&self, other: &Cow<'_, str>) -> bool

impl PartialEq<String> for ByteString

fn eq(&self, other: &String) -> bool

impl PartialEq<Vec<u8>> for ByteString

fn eq(&self, other: &Vec<u8>) -> bool

impl PartialEq<[u8]> for ByteString

fn eq(&self, other: &[u8]) -> bool

impl PartialEq<str> for ByteString

fn eq(&self, other: &str) -> bool

impl PartialOrd for ByteString

fn partial_cmp(&self, other: &ByteString) -> Option<Ordering>

impl PartialOrd<&ByteStr> for ByteString

fn partial_cmp(&self, other: &&ByteStr) -> Option<Ordering>

impl PartialOrd<ByteStr> for ByteString

fn partial_cmp(&self, other: &ByteStr) -> Option<Ordering>

impl PartialOrd<Cow<'_, ByteStr>> for ByteString

fn partial_cmp(&self, other: &Cow<'_, ByteStr>) -> Option<Ordering>

impl PartialOrd<Cow<'_, [u8]>> for ByteString

fn partial_cmp(&self, other: &Cow<'_, [u8]>) -> Option<Ordering>

impl PartialOrd<Cow<'_, str>> for ByteString

fn partial_cmp(&self, other: &Cow<'_, str>) -> Option<Ordering>

impl<'a> From<&'a ByteStr> for ByteString

fn from(s: &'a ByteStr) -> Self

impl<'a> FromIterator<&'a ByteStr> for ByteString

fn from_iter<T: IntoIterator<Item = &'a ByteStr>>(iter: T) -> Self

impl<'a> FromIterator<&'a [u8]> for ByteString

fn from_iter<T: IntoIterator<Item = &'a [u8]>>(iter: T) -> Self

impl<'a> FromIterator<&'a str> for ByteString

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

impl<const N: usize> PartialEq<&[u8; N]> for ByteString

fn eq(&self, other: &&[u8; N]) -> bool

impl<const N: usize> PartialEq<[u8; N]> for ByteString

fn eq(&self, other: &[u8; N]) -> bool

Auto Trait Implementations

impl Freeze for ByteString

impl RefUnwindSafe for ByteString

impl Send for ByteString

impl Sync for ByteString

impl Unpin for ByteString

impl UnsafeUnpin for ByteString

impl UnwindSafe for ByteString

Blanket Implementations

impl<P, T> Receiver for ByteString where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for ByteString where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for ByteString

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for ByteString where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ByteString

impl<T> ToOwned for ByteString where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn to_string(&self) -> String

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

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>