Struct bstring::bstring::BString [] [src]

pub struct BString { /* fields omitted */ }

A growable byte string of unknown encoding.

It is analogous to the standard String type.

Its borrowed slice counterpart is the bstr type.

Methods

impl BString
[src]

Creates a new empty BString.

Creates a new empty BString with the given capacity.

Returns a concatenated BString consisting of the given bstr values.

Examples

use bstring::BString;

assert_eq!(BString::concat(&["hello", "world"]), "helloworld");

Returns a BString consisting of the given bstr values, joined together with the given separator.

Examples

use bstring::BString;

assert_eq!(BString::join(" ", &["hello", "world"]), "hello world");

Creates a new BString from a pointer, length, and capacity.

Safety

This is unsafe due to a number of invariants that are not checked:

  • The memory at ptr needs to have been previously allocated by the same allocator the standard library uses.
  • length needs to be less than or equal to capacity.
  • capacity needs to be the correct value.

Returns a borrowed &bstr slice containing the entire string.

Returns a mutable &bstr slice containing the entire string.

Returns a mutable reference to the internal Vec<u8>.

This method is safe because BString does not enforce any invariants over the content of its buffer. Any otherwise safe modifications may be made to the returned Vec.

Consumes the BString and returns the internal Vec<u8>.

Attempts to the convert the BString into a String.

If the byte string does not contain valid UTF-8 data, an error is returned.

Appends bytes from a given byte string to this buffer.

Examples

use bstring::BString;

let mut bs = BString::from("Rebecca");

bs.push_str(" Bunch");

assert_eq!(bs, "Rebecca Bunch");

Returns the capacity of this BString, in bytes.

Ensures that the BString capacity is at least additional bytes greater than its current length.

Panics

If the new capacity overflows usize.

Ensures that the BString capacity is exactly additional bytes greater than its length.

Panics

If the new the capacity overflows usize.

Shrinks the capacity of the BString to match its length.

Appends the given byte to end of this BString.

Shortens the BString to the given length.

If new_len is greater than its current length, this has no effect.

This method does not affect the allocated capacity.

Examples

use bstring::BString;

let mut bs = BString::from("Josh Chan");

bs.truncate(4);

assert_eq!(bs, "Josh");

Removes and returns the last byte of the string.

Returns None if the string is empty.

Removes and returns the byte at the position idx.

Panics

If idx is greater than or equal to the current length.

Retains only the elements that satisfy the given predicate.

In other words, removes all elements for which f(&e) return false.

Examples

use bstring::BString;

let mut bs = BString::from("pretzel");

bs.retain(|&b| b != b'e');

assert_eq!(bs, "prtzl");

Inserts the given byte at position idx.

Inserts a byte string at position idx.

Examples

use bstring::BString;

let mut bs = BString::from("Covina");

bs.insert_str(0, "West ");

assert_eq!(bs, "West Covina");

Splits the BString into two at the given index.

Returns a newly allocated BString. self contains bytes [0, at) and the returned BString contains bytes [at, len).

The capacity of self is not affected.

Panics

If at is greater than the current length.

Truncates this BString, removing all contents.

The BString will have a length of zero, but its capacity will be unaffected.

Converts this BString into a Box<bstr>.

This will drop any excess capacity.

Methods from Deref<Target = bstr>

Returns the length of the string, in bytes.

Returns whether the string is empty.

Returns a borrowed reference to the internal byte slice.

Returns a mutable reference to the internal byte slice.

Returns a raw pointer to the contained buffer.

Returns a raw mutable pointer to the contained buffer.

Returns a newly allocated BString buffer for the

Attempts to convert the byte string to a str slice.

If the byte string does not contain valid UTF-8, an error is returned.

Converts the byte string to a str slice.

Safety

The byte string is assumed to contain valid UTF-8.

Converts the byte string a String.

During this conversion, any invalid UTF-8 sequences will be replaced with U+FFFD REPLACEMENT CHARACTER, which looks like this �

Returns an object that implements Display for safely printing byte strings that may contain non-UTF-8 data.

Returns the byte at the given index.

Returns None if idx is greater than or equal to the string length.

Returns the byte at the given index, bypassing bounds-checking.

Safety

The caller of this function must guarantee that idx is less than the byte string length.

Returns a subslice of this byte string, bypassing bounds-checking.

Safety

The caller of this function must guarantee that:

  • start is less than or equal to end
  • end is less than or equal to the byte string length

Returns a mutable subslice of this byte string, bypassing bounds-checking.

Safety

The caller of this function must guarantee that:

  • start is less than or equal to end
  • end is less than or equal to the byte string length

Returns a borrowed reference to the first byte in the string.

Returns None if the byte string is empty.

Returns a mutable reference to the first byte in the string.

Returns None if the byte string is empty.

Returns a borrowed reference to the last byte in the string.

Returns None if the byte string is empty.

Returns a mutable reference to the last byte in the string.

Returns None if the byte string is empty.

Returns an iterator over the bytes of this string.

The element type of the returned iterator is &u8.

Returns a mutable iterator over the bytes of this string.

The element type of the returned iterator is &mut u8.

Returns an iterator over the lines of this byte string.

Lines may end with either a newline (\n) or a carriage return followed by a line feed (\r\n).

Yielded subslices will not contain the line ending.

Returns a subslice with leading and trailing whitespace removed.

Returns a subslice with leading whitespace removed.

Returns a subslice with trailing whitespace removed.

Returns a subslice with all matching prefixes and suffixes removed.

Returns a subslice with all matching prefixes removed.

Returns a subslice with all matching suffixes removed.

Partitions the string using the given pattern.

The string is searched for the given pattern. If it is found, two subslices are returned: The portion of the string before the matching substring and the portion occurring after it.

Examples

use bstring::bstr;

let bs = <&bstr>::from("foo=bar=baz");

let (a, b) = bs.partition(b'=').unwrap();

assert_eq!(a, "foo");
assert_eq!(b, "bar=baz");

Partitions the string using the given pattern, searching from the end.

The string is searched for the given pattern, starting from the end. If it is found, two subslices are returned: The portion of the string before the matching substring and the portion occurring after it.

Examples

use bstring::bstr;

let bs = <&bstr>::from("foo=bar=baz");

let (a, b) = bs.rpartition(b'=').unwrap();

assert_eq!(a, "foo=bar");
assert_eq!(b, "baz");

Returns an iterator of subslices of this string, separated by a pattern.

Returns a reverse iterator of subslices of this string, separated by a pattern.

Returns an iterator of subslices of this string, separated by a pattern, limited to at most count items.

If count items are returned, the last item will contain the remainder of the string.

Returns a reverse iterator of subslices of this string, separated by a pattern, limited to at most count items.

If count items are returned, the last item will contain the remainder of the string.

Returns an iterator of subslices of this string, separated by a pattern.

Equivalent to split, except that the final subslice is skipped if it is empty.

Returns a reverse iterator of subslices of this string, separated by a pattern.

Equivalent to rsplit, except that the final subslice is skipped if it is empty.

Returns an iterator of delimited words.

This differs from split in that multiple occurances of a pattern will be considered as one.

Examples

use bstring::bstr;

let mut words = <&bstr>::from("   foo   bar   ").split_words(b' ');

assert_eq!(words.next().unwrap(), "foo");
assert_eq!(words.next().unwrap(), "bar");
assert_eq!(words.next(), None);

Returns an iterator over matches in the byte string.

Returns a reverse iterator over matches in the byte string.

Returns an iterator over matches in the byte string, including the index at which the match begins.

Returns a reverse iterator over matches in the byte string, including the index at which the match begins.

Returns the byte string divided into two at mid.

Panics

If mid is beyond the end of the byte string.

Returns the byte string divided into two at mid.

Panics

If mid is beyond the end of the byte string.

Returns the first byte and the rest, or None if the byte string is empty.

Returns the first byte and the rest, or None if the byte string is empty.

Returns the last byte and the rest, or None if the byte string is empty.

Returns the last byte and the rest, or None if the byte string is empty.

Returns whether the byte string contains the given pattern.

Returns whether the byte string starts with the given pattern.

Returns whether the byte string ends with the given pattern.

Returns the index of the first match of the given pattern.

Returns None if there is no match.

Returns the index of the first match of the given pattern, starting from the end.

Returns None if there is no match.

Returns a value parsed from the byte string, using the FromBStr trait

Converts a Box<bstr> into a BString.

Trait Implementations

impl Display for BString
[src]

Formats the value using the given formatter.

impl Clone for BString
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for BString
[src]

Returns the "default value" for a type. Read more

impl Hash for BString
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Deref for BString
[src]

The resulting type after dereferencing

The method called to dereference a value

impl DerefMut for BString
[src]

The method called to mutably dereference a value

impl<'a> From<&'a str> for BString
[src]

Performs the conversion.

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

Performs the conversion.

impl<'a> From<&'a bstr> for BString
[src]

Performs the conversion.

impl From<String> for BString
[src]

Performs the conversion.

impl From<Vec<u8>> for BString
[src]

Performs the conversion.

impl AsRef<bstr> for BString
[src]

Performs the conversion.

impl AsMut<bstr> for BString
[src]

Performs the conversion.

impl Borrow<bstr> for BString
[src]

Immutably borrows from an owned value. Read more

impl Debug for BString
[src]

Formats the value using the given formatter.

impl<'a> Add<&'a bstr> for BString
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<&'a str> for BString
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<&'a [u8]> for BString
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> AddAssign<&'a bstr> for BString
[src]

The method for the += operator

impl<'a> AddAssign<&'a str> for BString
[src]

The method for the += operator

impl<'a> AddAssign<&'a [u8]> for BString
[src]

The method for the += operator

impl Extend<u8> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<&'a u8> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<&'a bstr> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<BString> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<&'a str> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<String> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<&'a [u8]> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Extend<Vec<u8>> for BString
[src]

Extends a collection with the contents of an iterator. Read more

impl FromBStr for BString
[src]

Error type returned from a failed parsing attempt.

Parses a bstr to return this value.

impl FromIterator<u8> for BString
[src]

Creates a value from an iterator. Read more

impl Index<usize> for BString
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl Index<Range<usize>> for BString
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl Index<RangeFrom<usize>> for BString
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl Index<RangeTo<usize>> for BString
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl Index<RangeFull> for BString
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl IndexMut<usize> for BString
[src]

The method for the mutable indexing (container[index]) operation

impl IndexMut<Range<usize>> for BString
[src]

The method for the mutable indexing (container[index]) operation

impl IndexMut<RangeFrom<usize>> for BString
[src]

The method for the mutable indexing (container[index]) operation

impl IndexMut<RangeTo<usize>> for BString
[src]

The method for the mutable indexing (container[index]) operation

impl IndexMut<RangeFull> for BString
[src]

The method for the mutable indexing (container[index]) operation

impl<'a> IntoIterator for &'a BString
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a mut BString
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl Eq for BString
[src]

impl<'a, 'b> PartialEq<BString> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<bstr> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'a bstr> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<Cow<'a, bstr>> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<String> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<str> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'a str> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<Cow<'a, str>> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<Vec<u8>> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<[u8]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 0]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 0]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 1]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 1]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 2]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 2]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 3]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 3]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 4]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 4]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 5]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 5]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 6]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 6]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 7]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 7]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 8]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 8]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 9]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 9]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 10]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 10]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 11]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 11]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 12]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 12]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 13]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 13]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 14]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 14]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 15]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 15]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> PartialEq<[u8; 16]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'b> PartialEq<&'b [u8; 16]> for BString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Ord for BString
[src]

This method returns an Ordering between self and other. Read more

impl PartialOrd for BString
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more