Struct bstring::bstring::bstr [] [src]

pub struct bstr { /* fields omitted */ }

Byte string slice of unknown encoding.

It is analogous to the standard str type.

Its owned counterpart is the BString type.

Methods

impl bstr
[src]

Creates a new &bstr slice from a pointer and length.

Safety

This function is unsafe as there is no guarantee that the given pointer is valid for length bytes, nor whether the the lifetime inferred is a suitable lifetime for the returned slice.

Creates a new &mut bstr slice from a pointer and length.

Safety

This function is unsafe as there is no guarantee that the given pointer is valid for length bytes, nor whether the the lifetime inferred is a suitable lifetime for the returned slice.

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 bstr
[src]

Formats the value using the given formatter.

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

Performs the conversion.

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

Performs the conversion.

impl AsRef<bstr> for bstr
[src]

Performs the conversion.

impl AsMut<bstr> for bstr
[src]

Performs the conversion.

impl Debug for bstr
[src]

Formats the value using the given formatter.

impl Hash for bstr
[src]

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

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

impl<'a> Default for &'a bstr
[src]

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

impl ToOwned for bstr
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl Index<usize> for bstr
[src]

The returned type after indexing

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

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

The returned type after indexing

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

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

The returned type after indexing

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

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

The returned type after indexing

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

impl Index<RangeFull> for bstr
[src]

The returned type after indexing

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

impl IndexMut<usize> for bstr
[src]

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

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

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

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

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

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

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

impl IndexMut<RangeFull> for bstr
[src]

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

impl<'a> IntoIterator for &'a bstr
[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 bstr
[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 bstr
[src]

impl<'a, 'b> PartialEq<bstr> for bstr
[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<BString> for bstr
[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 bstr
[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 bstr
[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 bstr
[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 bstr
[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 &'a bstr
[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<BString> for &'a bstr
[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<'b, bstr>> for &'a bstr
[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 &'a bstr
[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 &'a bstr
[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<'b, str>> for &'a bstr
[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 bstr
[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 bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 &'a bstr
[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 bstr
[src]

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

impl PartialOrd for bstr
[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

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

Non-allocating substring search.

Will handle the pattern "" as returning empty matches at each character boundary.

Associated searcher for this pattern

Constructs the associated searcher from self and the haystack to search in. Read more

Checks whether the pattern matches at the front of the haystack

Checks whether the pattern matches at the back of the haystack

Checks whether the pattern matches anywhere in the haystack