Struct BString

struct BString { ... }

A wrapper for Vec<u8> that provides convenient string oriented trait impls.

A BString has ownership over its contents and corresponds to a growable or shrinkable buffer. Its borrowed counterpart is a BStr, called a byte string slice.

Using a BString is just like using a Vec<u8>, since BString implements Deref to Vec<u8>. So all methods available on Vec<u8> are also available on BString.

Examples

You can create a new BString from a Vec<u8> via a From impl:

use bstr::BString;

let s = BString::from("Hello, world!");

Deref

The BString type implements Deref and DerefMut, where the target types are &Vec<u8> and &mut Vec<u8>, respectively. Deref permits all of the methods defined on Vec<u8> to be implicitly callable on any BString.

For more information about how deref works, see the documentation for the std::ops::Deref trait.

Representation

A BString has the same representation as a Vec<u8> and a String. That is, it is made up of three word sized components: a pointer to a region of memory containing the bytes, a length and a capacity.

Implementations

impl BString

const fn new(bytes: Vec<u8>) -> BString

Constructs a new BString from the given Vec.

Examples

use bstr::BString;

let mut b = BString::new(Vec::with_capacity(10));

This function is const:

use bstr::BString;

const B: BString = BString::new(vec![]);

impl AsMut for BString

fn as_mut(self: &mut Self) -> &mut BStr

impl AsMut for BString

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

impl AsRef for BString

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

impl AsRef for BString

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

impl Borrow for BString

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

impl Borrow for BString

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

impl BorrowMut for BString

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

impl BorrowMut for BString

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

impl Clone for BString

fn clone(self: &Self) -> BString

impl Debug for BString

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

impl Default for BString

fn default() -> BString

impl Deref for BString

fn deref(self: &Self) -> &Vec<u8>

impl DerefMut for BString

fn deref_mut(self: &mut Self) -> &mut Vec<u8>

impl Display for BString

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

impl Eq for BString

impl Freeze for BString

impl From for BString

fn from(s: String) -> BString

impl From for BString

fn from(s: Vec<u8>) -> BString

impl FromIterator for BString

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

impl FromIterator for BString

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

impl FromIterator for BString

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

impl FromStr for BString

fn from_str(s: &str) -> Result<BString, Utf8Error>

impl Hash for BString

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

impl Ord for BString

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

impl PartialEq for BString

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

impl PartialOrd for BString

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

impl RefUnwindSafe for BString

impl Send for BString

impl Sync for BString

impl Unpin for BString

impl UnsafeUnpin for BString

impl UnwindSafe for BString

impl<'a> From for BString

fn from(s: &'a [u8]) -> BString

impl<'a> From for BString

fn from(s: &'a BStr) -> BString

impl<'a> From for BString

fn from(s: &'a str) -> BString

impl<'a> FromIterator for BString

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

impl<'a> FromIterator for BString

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

impl<'a> FromIterator for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialEq for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a> PartialOrd for BString

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

impl<'a, N: usize> From for BString

fn from(s: &'a [u8; N]) -> BString

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

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

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

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

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

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

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

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

impl<N: usize> From for BString

fn from(s: [u8; N]) -> BString

impl<P, T> Receiver for BString

impl<T> Any for BString

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for BString

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

impl<T> BorrowMut for BString

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

impl<T> CloneToUninit for BString

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

impl<T> From for BString

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for BString

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for BString

fn to_string(self: &Self) -> String

impl<T, U> Into for BString

fn into(self: 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 for BString

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

impl<T, U> TryInto for BString

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