Struct BString

#[repr(transparent)]
pub struct BString { /* private fields */ }

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![]);

Trait Implementations

impl AsMut<BStr> for BString

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

impl AsMut<[u8]> for BString

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

impl AsRef<BStr> for BString

fn as_ref(&self) -> &BStr

impl AsRef<[u8]> for BString

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

impl Borrow<BStr> for BString

fn borrow(&self) -> &BStr

impl Borrow<[u8]> for BString

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

impl BorrowMut<BStr> for BString

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

impl BorrowMut<[u8]> for BString

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

impl Clone for BString

fn clone(&self) -> BString

impl Debug for BString

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

impl Default for BString

fn default() -> BString

impl Deref for BString

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

impl DerefMut for BString

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

impl Display for BString

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

impl Eq for BString

impl From<String> for BString

fn from(s: String) -> BString

impl From<Vec<u8>> for BString

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

impl FromIterator<BString> for BString

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

impl FromIterator<char> for BString

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

impl FromIterator<u8> for BString

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

impl FromStr for BString

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

impl Hash for BString

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

impl Ord for BString

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

impl PartialEq for BString

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

impl PartialOrd for BString

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

impl<'a> From<&'a BStr> for BString

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

impl<'a> From<&'a [u8]> for BString

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

impl<'a> From<&'a str> for BString

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

impl<'a> FromIterator<&'a BStr> for BString

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

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

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

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

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

impl<'a> PartialEq<&'a BStr> for BString

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

impl<'a> PartialEq<&'a [u8]> for BString

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

impl<'a> PartialEq<&'a str> for BString

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

impl<'a> PartialEq<BStr> for BString

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

impl<'a> PartialEq<String> for BString

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

impl<'a> PartialEq<Vec<u8>> for BString

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

impl<'a> PartialEq<[u8]> for BString

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

impl<'a> PartialEq<str> for BString

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

impl<'a> PartialOrd<&'a BStr> for BString

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

impl<'a> PartialOrd<&'a [u8]> for BString

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

impl<'a> PartialOrd<&'a str> for BString

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

impl<'a> PartialOrd<BStr> for BString

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

impl<'a> PartialOrd<String> for BString

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

impl<'a> PartialOrd<Vec<u8>> for BString

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

impl<'a> PartialOrd<[u8]> for BString

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

impl<'a> PartialOrd<str> for BString

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

impl<'a, const N: usize> From<&'a [u8; N]> for BString

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

impl<'a, const N: usize> PartialEq<&'a [u8; N]> for BString

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

impl<'a, const N: usize> PartialEq<[u8; N]> for BString

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

impl<'a, const N: usize> PartialOrd<&'a [u8; N]> for BString

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

impl<'a, const N: usize> PartialOrd<[u8; N]> for BString

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

impl<const N: usize> From<[u8; N]> for BString

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

Auto Trait Implementations

impl Freeze for BString

impl RefUnwindSafe for BString

impl Send for BString

impl Sync for BString

impl Unpin for BString

impl UnsafeUnpin for BString

impl UnwindSafe for BString

Blanket Implementations

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

type Target = T;

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for BString

fn from(t: T) -> T

Returns the argument unchanged.

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

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

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

fn to_string(&self) -> String

impl<T, U> Into<U> for BString 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 BString where U: Into<T>,

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

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

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