Struct ByteStr
struct ByteStr(23118)
A wrapper for &[u8] representing a human-readable string that's conventionally, but not
always, UTF-8.
Unlike &str, 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.
For an owned, growable byte string buffer, use
ByteString.
ByteStr implements Deref to [u8], so all methods available on [u8] are available on
ByteStr.
Representation
A &ByteStr has the same representation as a &str. That is, a &ByteStr is a wide pointer
which includes a pointer to some bytes and a length.
Trait implementations
The ByteStr type has a number of trait implementations, and in particular, defines equality
and comparisons between &ByteStr, &str, and &[u8], for convenience.
The Debug implementation for ByteStr shows its bytes as a normal string, with invalid UTF-8
presented as hex escape sequences.
The Display implementation behaves as if the ByteStr were first lossily converted to a
str, with invalid UTF-8 presented as the Unicode replacement character (�).
Implementations
impl ByteStr
const fn new<B: ?Sized + ~const AsRef<[u8]>>(bytes: &B) -> &SelfCreates a
ByteStrslice from anything that can be converted to a byte slice.This is a zero-cost conversion.
Example
You can create a
ByteStrfrom a byte array, a byte slice or a string slice:# # use ByteStr; let a = new; let b = new; let c = new; assert_eq!; assert_eq!;const fn as_byte_str(self: &Self) -> &ByteStrReturns the same string as
&ByteStr.This method is redundant when used directly on
&ByteStr, but it helps dereferencing other "container" types, for exampleBox<ByteStr>orArc<ByteStr>.const fn as_mut_byte_str(self: &mut Self) -> &mut ByteStrReturns the same string as
&mut ByteStr.This method is redundant when used directly on
&mut ByteStr, but it helps dereferencing other "container" types, for exampleBox<ByteStr>orMutexGuard<ByteStr>.
impl AsMut for ByteStr
fn as_mut(self: &mut Self) -> &mut [u8]
impl AsRef for ByteStr
fn as_ref(self: &Self) -> &[u8]
impl AsRef for ByteStr
fn as_ref(self: &Self) -> &ByteStr
impl Borrow for ByteStr
fn borrow(self: &Self) -> &[u8]
impl BorrowMut for ByteStr
fn borrow_mut(self: &mut Self) -> &mut [u8]
impl CloneToUninit for crate::bstr::ByteStr
unsafe fn clone_to_uninit(self: &Self, dst: *mut u8)
impl Debug for ByteStr
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Deref for ByteStr
fn deref(self: &Self) -> &[u8]
impl DerefMut for ByteStr
fn deref_mut(self: &mut Self) -> &mut [u8]
impl DerefPure for ByteStr
impl Display for ByteStr
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Eq for crate::bstr::ByteStr
impl Freeze for ByteStr
impl Hash for crate::bstr::ByteStr
fn hash<H: hash::Hasher>(self: &Self, state: &mut H)
impl Ord for crate::bstr::ByteStr
fn cmp(self: &Self, other: &ByteStr) -> Ordering
impl PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &ByteStr) -> bool
impl PartialOrd for crate::bstr::ByteStr
fn partial_cmp(self: &Self, other: &ByteStr) -> Option<Ordering>
impl RefUnwindSafe for ByteStr
impl Send for ByteStr
impl Sized for ByteStr
impl Sync for ByteStr
impl Unpin for ByteStr
impl UnwindSafe for ByteStr
impl<'a> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &str) -> bool
impl<'a> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &&str) -> bool
impl<'a> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &[u8]) -> bool
impl<'a> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &&[u8]) -> bool
impl<I> Index for crate::bstr::ByteStr
fn index(self: &Self, index: I) -> &<I as >::Output
impl<I> IndexMut for crate::bstr::ByteStr
fn index_mut(self: &mut Self, index: I) -> &mut <I as >::Output
impl<N: usize> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &&[u8; N]) -> bool
impl<N: usize> PartialEq for crate::bstr::ByteStr
fn eq(self: &Self, other: &[u8; N]) -> bool
impl<P, T> Receiver for ByteStr
impl<T> Any for ByteStr
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ByteStr
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ByteStr
fn borrow_mut(self: &mut Self) -> &mut T