Struct BStr

struct BStr { ... }

A wrapper for &[u8] that provides convenient string oriented trait impls.

If you need ownership or a growable byte string buffer, then use BString.

Using a &BStr is just like using a &[u8], since BStr implements Deref to [u8]. So all methods available on [u8] are also available on BStr.

Representation

A &BStr has the same representation as a &str. That is, a &BStr is a fat pointer which consists of a pointer to some bytes and a length.

Trait implementations

The BStr type has a number of trait implementations, and in particular, defines equality and ordinal comparisons between &BStr, &str and &[u8] for convenience.

The Debug implementation for BStr shows its bytes as a normal string. For invalid UTF-8, hex escape sequences are used.

The Display implementation behaves as if BStr were first lossily converted to a str. Invalid UTF-8 bytes are substituted with the Unicode replacement codepoint, which looks like this: �.

Implementations

impl BStr

fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &BStr

Directly creates a BStr slice from anything that can be converted to a byte slice.

This is very similar to the B function, except this returns a &BStr instead of a &[u8].

This is a cost-free conversion.

Example

You can create BStr's from byte arrays, byte slices or even string slices:

use bstr::BStr;

let a = BStr::new(b"abc");
let b = BStr::new(&b"abc"[..]);
let c = BStr::new("abc");

assert_eq!(a, b);
assert_eq!(a, c);

impl AsMut for BStr

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

impl AsRef for BStr

fn as_ref(self: &Self) -> &BStr

impl AsRef for BStr

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

impl Borrow for BStr

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

impl BorrowMut for BStr

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

impl Debug for BStr

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

impl Deref for BStr

fn deref(self: &Self) -> &[u8]

impl DerefMut for BStr

fn deref_mut(self: &mut Self) -> &mut [u8]

impl Display for BStr

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

impl Eq for BStr

impl Freeze for BStr

impl Hash for BStr

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

impl Index for BStr

fn index(self: &Self, r: RangeToInclusive<usize>) -> &BStr

impl Index for BStr

fn index(self: &Self, r: RangeTo<usize>) -> &BStr

impl Index for BStr

fn index(self: &Self, r: RangeFrom<usize>) -> &BStr

impl Index for BStr

fn index(self: &Self, r: RangeInclusive<usize>) -> &BStr

impl Index for BStr

fn index(self: &Self, r: Range<usize>) -> &BStr

impl Index for BStr

fn index(self: &Self, _: RangeFull) -> &BStr

impl Index for BStr

fn index(self: &Self, idx: usize) -> &u8

impl IndexMut for BStr

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

impl IndexMut for BStr

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

impl IndexMut for BStr

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

impl IndexMut for BStr

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

impl IndexMut for BStr

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

impl IndexMut for BStr

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

impl IndexMut for BStr

fn index_mut(self: &mut Self, _: RangeFull) -> &mut BStr

impl Ord for BStr

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

impl PartialEq for BStr

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

impl PartialOrd for BStr

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

impl RefUnwindSafe for BStr

impl Send for BStr

impl Sized for BStr

impl Sync for BStr

impl ToOwned for BStr

fn to_owned(self: &Self) -> BString

impl Unpin for BStr

impl UnsafeUnpin for BStr

impl UnwindSafe for BStr

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialEq for BStr

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

impl<'a> PartialOrd for BStr

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

impl<'a> PartialOrd for BStr

fn partial_cmp(self: &Self, other: &Vec<u8>) -> Option<Ordering>

impl<'a> PartialOrd for BStr

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

impl<'a> PartialOrd for BStr

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

impl<'a> PartialOrd for BStr

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

impl<'a> PartialOrd for BStr

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

impl<'a> PartialOrd for BStr

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

impl<'a, N: usize> PartialEq for BStr

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

impl<'a, N: usize> PartialEq for BStr

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

impl<'a, N: usize> PartialOrd for BStr

fn partial_cmp(self: &Self, other: &&'a [u8; N]) -> Option<Ordering>

impl<'a, N: usize> PartialOrd for BStr

fn partial_cmp(self: &Self, other: &[u8; N]) -> Option<Ordering>

impl<P, T> Receiver for BStr

impl<T> Any for BStr

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for BStr

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for BStr

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

impl<T> ToString for BStr

fn to_string(self: &Self) -> String