[][src]Struct bstr::BStr

pub struct BStr { /* fields omitted */ }

A byte string slice that is conventionally UTF-8.

A byte string slice is the core string type in this library, and is usually seen in its borrowed form, &BStr. The principle difference between a &BStr and a &str (Rust's standard Unicode string slice) is that a &BStr is only conventionally UTF-8, where as a &str is guaranteed to always be valid UTF-8.

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

Literals

A byte string literal has type &'static BStr. The most convenient way to write a byte string literal is by using the short-hand B constructor function:

use bstr::{B, BStr};

// A byte string literal can be constructed from a normal Unicode string.
let s = B("a byte string literal");
// A byte string literal can also be constructed from a Rust byte string.
let s = B(b"another byte string literal");

// BStr::new can also be used:
let s = BStr::new("a byte string literal");
let s = BStr::new(b"another byte string literal");

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: �.

Indexing and slicing

A BStr implements indexing and slicing using [..] notation. Unlike the standard str type, the BStr type permits callers to index individual bytes. For example:

use bstr::B;

let s = B("foo☃bar");
assert_eq!(&s[0..3], "foo");
assert_eq!(s[2], b'o');
assert_eq!(&s[3..6], "☃");

// Nothing stops you from indexing or slicing invalid UTF-8.
assert_eq!(s[3], b'\xE2');
assert_eq!(&s[3..5], B(b"\xE2\x98"));

Methods

impl BStr[src]

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

Create a byte string slice from anything that can be borrowed as a sequence of bytes. This includes, but is not limited to, &Vec<u8>, &[u8], &String and &str.

Examples

Basic usage:

use bstr::BStr;

assert_eq!("abc", BStr::new("abc"));
assert_eq!("abc", BStr::new(b"abc"));

pub fn new_mut<B: ?Sized + AsMut<[u8]>>(bytes: &mut B) -> &mut BStr[src]

Create a mutable byte string slice from anything that can be borrowed as a sequence of bytes. This includes, but is not limited to, &mut Vec<u8> and &mut [u8].

Examples

Basic usage:

use bstr::BStr;

assert_eq!("abc", BStr::new("abc"));
assert_eq!("abc", BStr::new(b"abc"));

pub fn from_bytes(slice: &[u8]) -> &BStr[src]

Create an immutable byte string slice from an immutable byte slice.

Examples

Basic usage:

use bstr::BStr;

let bytes = &[b'a'];
let bs = BStr::from_bytes(bytes);
assert_eq!("a", bs);

pub fn from_bytes_mut(slice: &mut [u8]) -> &mut BStr[src]

Create a mutable byte string slice from a mutable byte slice.

Examples

Basic usage:

use bstr::BStr;

let bytes = &mut [b'a'];
{
    let bs = BStr::from_bytes_mut(bytes);
    bs[0] = b'b';
}
assert_eq!(b"b", bytes);

pub unsafe fn from_raw_parts<'a>(data: *const u8, len: usize) -> &'a BStr[src]

Create a byte string from its constituent pointer and length, where the length is the number of bytes in the byte string.

Safety

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

data must be a non-null pointer, even for a zero length slice. A pointer that is usable for zero-length slices can be obtaining from the standard library's NonNull::dangling() constructor.

The total size of the given slice must be no larger than isize::MAX bytes in memory.

Caveat

The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it's suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.

Examples

Basic usage:

use bstr::BStr;

// manifest a byte string from a single byte
let x = b'Z';
let ptr = &x as *const u8;
let s = unsafe { BStr::from_raw_parts(ptr, 1) };
assert_eq!(s, "Z");

pub unsafe fn from_raw_parts_mut<'a>(data: *mut u8, len: usize) -> &'a mut BStr[src]

Create a mutable byte string from its constituent pointer and length, where the length is the number of bytes in the byte string.

Safety

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

data must be a non-null pointer, even for a zero length slice. A pointer that is usable for zero-length slices can be obtaining from the standard library's NonNull::dangling() constructor.

The total size of the given slice must be no larger than isize::MAX bytes in memory.

The above reasons are the same as for from_raw_parts. In addition, for this constructor, callers must guarantee that the mutable slice returned is not aliased with any other reference.

Caveat

The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it's suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.

Examples

Basic usage:

use std::mem;
use bstr::{BStr, BString};

// For demonstration purposes, get a mutable pointer to a byte string.
let mut buf = BString::from("bar");
let ptr = buf.as_mut_ptr();
// Drop buf without deallocating, to avoid &mut aliasing.
mem::forget(buf);

// Now convert it to a mutable byte string from the raw pointer.
let mut s = unsafe { BStr::from_raw_parts_mut(ptr, 3) };
s.make_ascii_uppercase();
assert_eq!(s, "BAR");

pub fn from_os_str(os_str: &OsStr) -> Option<&BStr>[src]

Create an immutable byte string from an OS string slice.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns None if the given OS string is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. Not all such sequences can be transcoded to valid UTF-8.)

Examples

Basic usage:

use std::ffi::OsStr;

use bstr::BStr;

let os_str = OsStr::new("foo");
let bs = BStr::from_os_str(os_str).expect("should be valid UTF-8");
assert_eq!(bs, "foo");

pub fn from_path(path: &Path) -> Option<&BStr>[src]

Create an immutable byte string from a file path.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns None if the given path is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. Not all such sequences can be transcoded to valid UTF-8.)

Examples

Basic usage:

use std::path::Path;

use bstr::BStr;

let path = Path::new("foo");
let bs = BStr::from_path(path).expect("should be valid UTF-8");
assert_eq!(bs, "foo");

pub fn len(&self) -> usize[src]

Returns the length, in bytes, of this byte string.

Examples

Basic usage:

use bstr::BStr;

assert_eq!(0, BStr::new("").len());
assert_eq!(3, BStr::new("abc").len());
assert_eq!(8, BStr::new("☃βツ").len());

pub fn is_empty(&self) -> bool[src]

Returns true if and only if the length of this byte string is zero.

Examples

Basic usage:

use bstr::BStr;

assert!(BStr::new("").is_empty());
assert!(!BStr::new("abc").is_empty());

pub fn as_bytes(&self) -> &[u8][src]

Returns an immutable byte slice of this BStr's contents.

Examples

Basic usage:

use bstr::B;

let s = B("hello");

assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());

pub fn as_bytes_mut(&mut self) -> &mut [u8][src]

Returns a mutable byte slice of this BStr's contents.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("hello");
s.as_bytes_mut()[1] = b'a';

assert_eq!(&[104, 97, 108, 108, 111], s.as_bytes());

pub fn to_bstring(&self) -> BString[src]

Create a new owned byte string from this byte string slice.

Examples

Basic usage:

use bstr::BStr;

let s = BStr::new("abc");
let mut owned = s.to_bstring();
owned.push_char('d');
assert_eq!("abcd", owned);

pub fn to_str(&self) -> Result<&str, Utf8Error>[src]

Safely convert this byte string into a &str if it's valid UTF-8.

If this byte string is not valid UTF-8, then an error is returned. The error returned indicates the first invalid byte found and the length of the error.

In cases where a lossy conversion to &str is acceptable, then use one of the to_str_lossy or to_str_lossy_into methods.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("☃βツ").to_str()?;
assert_eq!("☃βツ", s);

let mut bstring = BString::from("☃βツ");
bstring.push_byte(b'\xFF');
let err = bstring.to_str().unwrap_err();
assert_eq!(8, err.valid_up_to());

pub unsafe fn to_str_unchecked(&self) -> &str[src]

Unsafely convert this byte string into a &str, without checking for valid UTF-8.

Safety

Callers must ensure that this byte string is valid UTF-8 before calling this method. Converting a byte string into a &str that is not valid UTF-8 is considered undefined behavior.

This routine is useful in performance sensitive contexts where the UTF-8 validity of the byte string is already known and it is undesirable to pay the cost of an additional UTF-8 validation check that to_str performs.

Examples

Basic usage:

use bstr::{B, BString};

// SAFETY: This is safe because string literals are guaranteed to be
// valid UTF-8 by the Rust compiler.
let s = unsafe { B("☃βツ").to_str_unchecked() };
assert_eq!("☃βツ", s);

pub fn to_str_lossy(&self) -> Cow<str>[src]

Convert this byte string to a valid UTF-8 string by replacing invalid UTF-8 bytes with the Unicode replacement codepoint (U+FFFD).

If the byte string is already valid UTF-8, then no copying or allocation is performed and a borrrowed string slice is returned. If the byte string is not valid UTF-8, then an owned string buffer is returned with invalid bytes replaced by the replacement codepoint.

This method uses the "substitution of maximal subparts" (Unicode Standard, Chapter 3, Section 9) strategy for inserting the replacement codepoint. Specifically, a replacement codepoint is inserted whenever a byte is found that cannot possibly lead to a valid code unit sequence. If there were previous bytes that represented a prefix of a well-formed code unit sequence, then all of those bytes are substituted with a single replacement codepoint. The "substitution of maximal subparts" strategy is the same strategy used by W3C's Encoding standard. For a more precise description of the maximal subpart strategy, see the Unicode Standard, Chapter 3, Section 9. See also Public Review Issue #121.

N.B. Rust's standard library also appears to use the same strategy, but it does not appear to be an API guarantee.

Examples

Basic usage:

use std::borrow::Cow;
use bstr::BString;

let mut bstring = BString::from("☃βツ");
assert_eq!(Cow::Borrowed("☃βツ"), bstring.to_str_lossy());

// Add a byte that makes the sequence invalid.
bstring.push_byte(b'\xFF');
assert_eq!(Cow::Borrowed("☃βツ\u{FFFD}"), bstring.to_str_lossy());

This demonstrates the "maximal subpart" substitution logic.

use bstr::B;

// \x61 is the ASCII codepoint for 'a'.
// \xF1\x80\x80 is a valid 3-byte code unit prefix.
// \xE1\x80 is a valid 2-byte code unit prefix.
// \xC2 is a valid 1-byte code unit prefix.
// \x62 is the ASCII codepoint for 'b'.
//
// In sum, each of the prefixes is replaced by a single replacement
// codepoint since none of the prefixes are properly completed. This
// is in contrast to other strategies that might insert a replacement
// codepoint for every single byte.
let bs = B(b"\x61\xF1\x80\x80\xE1\x80\xC2\x62");
assert_eq!("a\u{FFFD}\u{FFFD}\u{FFFD}b", bs.to_str_lossy());

pub fn to_str_lossy_into(&self, dest: &mut String)[src]

Copy the contents of this byte string into the given owned string buffer, while replacing invalid UTF-8 code unit sequences with the Unicode replacement codepoint (U+FFFD).

This method uses the same "substitution of maximal subparts" strategy for inserting the replacement codepoint as the to_str_lossy method.

This routine is useful for amortizing allocation. However, unlike to_str_lossy, this routine will always copy the contents of this byte string into the destination buffer, even if this byte string is valid UTF-8.

Examples

Basic usage:

use std::borrow::Cow;
use bstr::BString;

let mut bstring = BString::from("☃βツ");
// Add a byte that makes the sequence invalid.
bstring.push_byte(b'\xFF');

let mut dest = String::new();
bstring.to_str_lossy_into(&mut dest);
assert_eq!("☃βツ\u{FFFD}", dest);

pub fn to_os_str(&self) -> Result<&OsStr, Utf8Error>[src]

Create an OS string slice from this byte string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns a UTF-8 decoding error if this byte string is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. There is no obvious mapping from an arbitrary sequence of 8-bit integers to an arbitrary sequence of 16-bit integers.)

Examples

Basic usage:

use bstr::B;

let bs = B("foo");
let os_str = bs.to_os_str().expect("should be valid UTF-8");
assert_eq!(os_str, "foo");

pub fn to_os_str_lossy(&self) -> Cow<OsStr>[src]

Lossily create an OS string slice from this byte string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this will perform a UTF-8 check and lossily convert this byte string into valid UTF-8 using the Unicode replacement codepoint.

Note that this can prevent the correct roundtripping of file paths on non-Unix systems such as Windows, where file paths are an arbitrary sequence of 16-bit integers.

Examples

Basic usage:

use bstr::B;

let bs = B(b"foo\xFFbar");
let os_str = bs.to_os_str_lossy();
assert_eq!(os_str.to_string_lossy(), "foo\u{FFFD}bar");

pub fn to_path(&self) -> Result<&Path, Utf8Error>[src]

Create a path slice from this byte string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns a UTF-8 decoding error if this byte string is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. There is no obvious mapping from an arbitrary sequence of 8-bit integers to an arbitrary sequence of 16-bit integers.)

Examples

Basic usage:

use bstr::B;

let bs = B("foo");
let path = bs.to_path().expect("should be valid UTF-8");
assert_eq!(path.as_os_str(), "foo");

pub fn to_path_lossy(&self) -> Cow<Path>[src]

Lossily create a path slice from this byte string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this will perform a UTF-8 check and lossily convert this byte string into valid UTF-8 using the Unicode replacement codepoint.

Note that this can prevent the correct roundtripping of file paths on non-Unix systems such as Windows, where file paths are an arbitrary sequence of 16-bit integers.

Examples

Basic usage:

use bstr::B;

let bs = B(b"foo\xFFbar");
let path = bs.to_path_lossy();
assert_eq!(path.to_string_lossy(), "foo\u{FFFD}bar");

pub fn repeat(&self, n: usize) -> BString[src]

Create a new BString by repeating this byte string n times.

Panics

This function panics if the capacity of the new BString would overflow.

Examples

Basic usage:

use bstr::B;

assert_eq!("foofoofoofoo", B("foo").repeat(4));
assert_eq!("", B("foo").repeat(0));

pub fn contains<B: AsRef<[u8]>>(&self, needle: B) -> bool[src]

Returns true if and only if this byte string contains the given needle.

Examples

Basic usage:

use bstr::B;

assert!(B("foo bar").contains("foo"));
assert!(B("foo bar").contains("bar"));
assert!(!B("foo").contains("foobar"));

pub fn starts_with<B: AsRef<[u8]>>(&self, prefix: B) -> bool[src]

Returns true if and only if this byte string has the given prefix.

Examples

Basic usage:

use bstr::B;

assert!(B("foo bar").starts_with("foo"));
assert!(!B("foo bar").starts_with("bar"));
assert!(!B("foo").starts_with("foobar"));

pub fn ends_with<B: AsRef<[u8]>>(&self, suffix: B) -> bool[src]

Returns true if and only if this byte string has the given suffix.

Examples

Basic usage:

use bstr::B;

assert!(B("foo bar").ends_with("bar"));
assert!(!B("foo bar").ends_with("foo"));
assert!(!B("bar").ends_with("foobar"));

pub fn find<B: AsRef<[u8]>>(&self, needle: B) -> Option<usize>[src]

Returns the index of the first occurrence of the given needle.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Note that if you're are searching for the same needle in many different small haystacks, it may be faster to initialize a Finder once, and reuse it for each search.

Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

Examples

Basic usage:

use bstr::B;

let s = B("foo bar baz");
assert_eq!(Some(0), s.find("foo"));
assert_eq!(Some(4), s.find("bar"));
assert_eq!(None, s.find("quux"));

pub fn rfind<B: AsRef<[u8]>>(&self, needle: B) -> Option<usize>[src]

Returns the index of the last occurrence of the given needle.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Note that if you're are searching for the same needle in many different small haystacks, it may be faster to initialize a FinderReverse once, and reuse it for each search.

Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

Examples

Basic usage:

use bstr::B;

let s = B("foo bar baz");
assert_eq!(Some(0), s.rfind("foo"));
assert_eq!(Some(4), s.rfind("bar"));
assert_eq!(Some(8), s.rfind("ba"));
assert_eq!(None, s.rfind("quux"));

Important traits for Find<'a>
pub fn find_iter<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    needle: &'a B
) -> Find<'a>
[src]

Returns an iterator of the non-overlapping occurrences of the given needle. The iterator yields byte offset positions indicating the start of each match.

Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

Examples

Basic usage:

use bstr::B;

let s = B("foo bar foo foo quux foo");
let matches: Vec<usize> = s.find_iter("foo").collect();
assert_eq!(matches, vec![0, 8, 12, 21]);

An empty string matches at every position, including the position immediately following the last byte:

use bstr::B;

let matches: Vec<usize> = B("foo").find_iter("").collect();
assert_eq!(matches, vec![0, 1, 2, 3]);

let matches: Vec<usize> = B("").find_iter("").collect();
assert_eq!(matches, vec![0]);

Important traits for FindReverse<'a>
pub fn rfind_iter<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    needle: &'a B
) -> FindReverse<'a>
[src]

Returns an iterator of the non-overlapping occurrences of the given needle in reverse. The iterator yields byte offset positions indicating the start of each match.

Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

Examples

Basic usage:

use bstr::B;

let s = B("foo bar foo foo quux foo");
let matches: Vec<usize> = s.rfind_iter("foo").collect();
assert_eq!(matches, vec![21, 12, 8, 0]);

An empty string matches at every position, including the position immediately following the last byte:

use bstr::B;

let matches: Vec<usize> = B("foo").rfind_iter("").collect();
assert_eq!(matches, vec![3, 2, 1, 0]);

let matches: Vec<usize> = B("").rfind_iter("").collect();
assert_eq!(matches, vec![0]);

pub fn find_byte(&self, byte: u8) -> Option<usize>[src]

Returns the index of the first occurrence of the given byte. If the byte does not occur in this byte string, then None is returned.

Examples

Basic usage:

use bstr::B;

assert_eq!(Some(10), B("foo bar baz").find_byte(b'z'));
assert_eq!(None, B("foo bar baz").find_byte(b'y'));

pub fn rfind_byte(&self, byte: u8) -> Option<usize>[src]

Returns the index of the last occurrence of the given byte. If the byte does not occur in this byte string, then None is returned.

Examples

Basic usage:

use bstr::B;

assert_eq!(Some(10), B("foo bar baz").rfind_byte(b'z'));
assert_eq!(None, B("foo bar baz").rfind_byte(b'y'));

pub fn find_char(&self, ch: char) -> Option<usize>[src]

Returns the index of the first occurrence of the given codepoint. If the codepoint does not occur in this byte string, then None is returned.

Note that if one searches for the replacement codepoint, \u{FFFD}, then only explicit occurrences of that encoding will be found. Invalid UTF-8 sequences will not be matched.

Examples

Basic usage:

use bstr::B;

assert_eq!(Some(10), B("foo bar baz").find_char('z'));
assert_eq!(Some(4), B("αβγγδ").find_char('γ'));
assert_eq!(None, B("foo bar baz").find_char('y'));

pub fn rfind_char(&self, ch: char) -> Option<usize>[src]

Returns the index of the last occurrence of the given codepoint. If the codepoint does not occur in this byte string, then None is returned.

Note that if one searches for the replacement codepoint, \u{FFFD}, then only explicit occurrences of that encoding will be found. Invalid UTF-8 sequences will not be matched.

Examples

Basic usage:

use bstr::B;

assert_eq!(Some(10), B("foo bar baz").rfind_char('z'));
assert_eq!(Some(6), B("αβγγδ").rfind_char('γ'));
assert_eq!(None, B("foo bar baz").rfind_char('y'));

Important traits for Fields<'a>
pub fn fields(&self) -> Fields[src]

Returns an iterator over the fields in a byte string, separated by contiguous whitespace.

Example

Basic usage:

use bstr::{B, BStr};

let s = B("  foo\tbar\t\u{2003}\nquux   \n");
let fields: Vec<&BStr> = s.fields().collect();
assert_eq!(fields, vec!["foo", "bar", "quux"]);

A byte string consisting of just whitespace yields no elements:

use bstr::B;

assert_eq!(0, B("  \n\t\u{2003}\n  \t").fields().count());

Important traits for FieldsWith<'a, F>
pub fn fields_with<F: FnMut(char) -> bool>(&self, f: F) -> FieldsWith<F>[src]

Returns an iterator over the fields in a byte string, separated by contiguous codepoints satisfying the given predicate.

If this byte

Example

Basic usage:

use bstr::{B, BStr};

let s = B("123foo999999bar1quux123456");
let fields: Vec<&BStr> = s.fields_with(|c| c.is_numeric()).collect();
assert_eq!(fields, vec!["foo", "bar", "quux"]);

A byte string consisting of all codepoints satisfying the predicate yields no elements:

use bstr::B;

assert_eq!(0, B("1911354563").fields_with(|c| c.is_numeric()).count());

Important traits for Split<'a>
pub fn split<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    splitter: &'a B
) -> Split<'a>
[src]

Returns an iterator over substrings of this byte string, separated by the given byte string. Each element yielded is guaranteed not to include the splitter substring.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Examples

Basic usage:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("Mary had a little lamb").split(" ").collect();
assert_eq!(x, vec!["Mary", "had", "a", "little", "lamb"]);

let x: Vec<&BStr> = B("").split("X").collect();
assert_eq!(x, vec![""]);

let x: Vec<&BStr> = B("lionXXtigerXleopard").split("X").collect();
assert_eq!(x, vec!["lion", "", "tiger", "leopard"]);

let x: Vec<&BStr> = B("lion::tiger::leopard").split("::").collect();
assert_eq!(x, vec!["lion", "tiger", "leopard"]);

If a string contains multiple contiguous separators, you will end up with empty strings yielded by the iterator:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("||||a||b|c").split("|").collect();
assert_eq!(x, vec!["", "", "", "", "a", "", "b", "c"]);

let x: Vec<&BStr> = B("(///)").split("/").collect();
assert_eq!(x, vec!["(", "", "", ")"]);

Separators at the start or end of a string are neighbored by empty strings.

use bstr::{B, BStr};

let x: Vec<&BStr> = B("010").split("0").collect();
assert_eq!(x, vec!["", "1", ""]);

When the empty string is used as a separator, it splits every byte in the byte string, along with the beginning and end of the byte string.

use bstr::{B, BStr};

let x: Vec<&BStr> = B("rust").split("").collect();
assert_eq!(x, vec!["", "r", "u", "s", "t", ""]);

// Splitting by an empty string is not UTF-8 aware. Elements yielded
// may not be valid UTF-8!
let x: Vec<&BStr> = B("☃").split("").collect();
assert_eq!(x, vec![B(""), B(b"\xE2"), B(b"\x98"), B(b"\x83"), B("")]);

Contiguous separators, especially whitespace, can lead to possibly surprising behavior. For example, this code is correct:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("    a  b c").split(" ").collect();
assert_eq!(x, vec!["", "", "", "", "a", "", "b", "c"]);

It does not give you ["a", "b", "c"]. For that behavior, use fields instead.

Important traits for SplitReverse<'a>
pub fn rsplit<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    splitter: &'a B
) -> SplitReverse<'a>
[src]

Returns an iterator over substrings of this byte string, separated by the given byte string, in reverse. Each element yielded is guaranteed not to include the splitter substring.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Examples

Basic usage:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("Mary had a little lamb").rsplit(" ").collect();
assert_eq!(x, vec!["lamb", "little", "a", "had", "Mary"]);

let x: Vec<&BStr> = B("").rsplit("X").collect();
assert_eq!(x, vec![""]);

let x: Vec<&BStr> = B("lionXXtigerXleopard").rsplit("X").collect();
assert_eq!(x, vec!["leopard", "tiger", "", "lion"]);

let x: Vec<&BStr> = B("lion::tiger::leopard").rsplit("::").collect();
assert_eq!(x, vec!["leopard", "tiger", "lion"]);

If a string contains multiple contiguous separators, you will end up with empty strings yielded by the iterator:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("||||a||b|c").rsplit("|").collect();
assert_eq!(x, vec!["c", "b", "", "a", "", "", "", ""]);

let x: Vec<&BStr> = B("(///)").rsplit("/").collect();
assert_eq!(x, vec![")", "", "", "("]);

Separators at the start or end of a string are neighbored by empty strings.

use bstr::{B, BStr};

let x: Vec<&BStr> = B("010").rsplit("0").collect();
assert_eq!(x, vec!["", "1", ""]);

When the empty string is used as a separator, it splits every byte in the byte string, along with the beginning and end of the byte string.

use bstr::{B, BStr};

let x: Vec<&BStr> = B("rust").rsplit("").collect();
assert_eq!(x, vec!["", "t", "s", "u", "r", ""]);

// Splitting by an empty string is not UTF-8 aware. Elements yielded
// may not be valid UTF-8!
let x: Vec<&BStr> = B("☃").rsplit("").collect();
assert_eq!(x, vec![B(""), B(b"\x83"), B(b"\x98"), B(b"\xE2"), B("")]);

Contiguous separators, especially whitespace, can lead to possibly surprising behavior. For example, this code is correct:

use bstr::{B, BStr};

let x: Vec<&BStr> = B("    a  b c").rsplit(" ").collect();
assert_eq!(x, vec!["c", "b", "", "a", "", "", "", ""]);

It does not give you ["a", "b", "c"].

Important traits for SplitN<'a>
pub fn splitn<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    limit: usize,
    splitter: &'a B
) -> SplitN<'a>
[src]

Returns an iterator of at most limit substrings of this byte string, separated by the given byte string. If limit substrings are yielded, then the last substring will contain the remainder of this byte string.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Examples

Basic usage:

use bstr::{B, BStr};

let x: Vec<_> = B("Mary had a little lamb").splitn(3, " ").collect();
assert_eq!(x, vec!["Mary", "had", "a little lamb"]);

let x: Vec<_> = B("").splitn(3, "X").collect();
assert_eq!(x, vec![""]);

let x: Vec<_> = B("lionXXtigerXleopard").splitn(3, "X").collect();
assert_eq!(x, vec!["lion", "", "tigerXleopard"]);

let x: Vec<_> = B("lion::tiger::leopard").splitn(2, "::").collect();
assert_eq!(x, vec!["lion", "tiger::leopard"]);

let x: Vec<_> = B("abcXdef").splitn(1, "X").collect();
assert_eq!(x, vec!["abcXdef"]);

let x: Vec<_> = B("abcXdef").splitn(0, "X").collect();
assert!(x.is_empty());

Important traits for SplitNReverse<'a>
pub fn rsplitn<'a, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    limit: usize,
    splitter: &'a B
) -> SplitNReverse<'a>
[src]

Returns an iterator of at most limit substrings of this byte string, separated by the given byte string, in reverse. If limit substrings are yielded, then the last substring will contain the remainder of this byte string.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str, &BStr, and of course, &[u8] itself.

Examples

Basic usage:

use bstr::{B, BStr};

let x: Vec<_> = B("Mary had a little lamb").rsplitn(3, " ").collect();
assert_eq!(x, vec!["lamb", "little", "Mary had a"]);

let x: Vec<_> = B("").rsplitn(3, "X").collect();
assert_eq!(x, vec![""]);

let x: Vec<_> = B("lionXXtigerXleopard").rsplitn(3, "X").collect();
assert_eq!(x, vec!["leopard", "tiger", "lionX"]);

let x: Vec<_> = B("lion::tiger::leopard").rsplitn(2, "::").collect();
assert_eq!(x, vec!["leopard", "lion::tiger"]);

let x: Vec<_> = B("abcXdef").rsplitn(1, "X").collect();
assert_eq!(x, vec!["abcXdef"]);

let x: Vec<_> = B("abcXdef").rsplitn(0, "X").collect();
assert!(x.is_empty());

pub fn replace<N: AsRef<[u8]>, R: AsRef<[u8]>>(
    &self,
    needle: N,
    replacement: R
) -> BString
[src]

Replace all matches of the given needle with the given replacement, and the result as a new BString.

This routine is useful as a convenience. If you need to reuse an allocation, use replace_into instead.

Examples

Basic usage:

use bstr::B;

let s = B("this is old").replace("old", "new");
assert_eq!(s, "this is new");

When the pattern doesn't match:

use bstr::B;

let s = B("this is old").replace("nada nada", "limonada");
assert_eq!(s, "this is old");

When the needle is an empty string:

use bstr::B;

let s = B("foo").replace("", "Z");
assert_eq!(s, "ZfZoZoZ");

pub fn replacen<N: AsRef<[u8]>, R: AsRef<[u8]>>(
    &self,
    needle: N,
    replacement: R,
    limit: usize
) -> BString
[src]

Replace up to limit matches of the given needle with the given replacement, and the result as a new BString.

This routine is useful as a convenience. If you need to reuse an allocation, use replacen_into instead.

Examples

Basic usage:

use bstr::B;

let s = B("foofoo").replacen("o", "z", 2);
assert_eq!(s, "fzzfoo");

When the pattern doesn't match:

use bstr::B;

let s = B("foofoo").replacen("a", "z", 2);
assert_eq!(s, "foofoo");

When the needle is an empty string:

use bstr::B;

let s = B("foo").replacen("", "Z", 2);
assert_eq!(s, "ZfZoo");

pub fn replace_into<N: AsRef<[u8]>, R: AsRef<[u8]>>(
    &self,
    needle: N,
    replacement: R,
    dest: &mut BString
)
[src]

Replace all matches of the given needle with the given replacement, and write the result into the provided BString.

This does not clear dest before writing to it.

This routine is useful for reusing allocation. For a more convenient API, use replace instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("this is old");

let mut dest = BString::new();
s.replace_into("old", "new", &mut dest);
assert_eq!(dest, "this is new");

When the pattern doesn't match:

use bstr::{B, BString};

let s = B("this is old");

let mut dest = BString::new();
s.replace_into("nada nada", "limonada", &mut dest);
assert_eq!(dest, "this is old");

When the needle is an empty string:

use bstr::{B, BString};

let s = B("foo");

let mut dest = BString::new();
s.replace_into("", "Z", &mut dest);
assert_eq!(dest, "ZfZoZoZ");

pub fn replacen_into<N: AsRef<[u8]>, R: AsRef<[u8]>>(
    &self,
    needle: N,
    replacement: R,
    limit: usize,
    dest: &mut BString
)
[src]

Replace up to limit matches of the given needle with the given replacement, and write the result into the provided BString.

This does not clear dest before writing to it.

This routine is useful for reusing allocation. For a more convenient API, use replace instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("foofoo");

let mut dest = BString::new();
s.replacen_into("o", "z", 2, &mut dest);
assert_eq!(dest, "fzzfoo");

When the pattern doesn't match:

use bstr::{B, BString};

let s = B("foofoo");

let mut dest = BString::new();
s.replacen_into("a", "z", 2, &mut dest);
assert_eq!(dest, "foofoo");

When the needle is an empty string:

use bstr::{B, BString};

let s = B("foo");

let mut dest = BString::new();
s.replacen_into("", "Z", 2, &mut dest);
assert_eq!(dest, "ZfZoo");

Important traits for Bytes<'a>
pub fn bytes(&self) -> Bytes[src]

Returns an iterator over the bytes in this byte string.

Examples

Basic usage:

use bstr::B;

let bs = B("foobar");
let bytes: Vec<u8> = bs.bytes().collect();
assert_eq!(bytes, bs);

Important traits for Chars<'a>
pub fn chars(&self) -> Chars[src]

Returns an iterator over the Unicode scalar values in this byte string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

Examples

Basic usage:

use bstr::B;

let bs = B(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");
let chars: Vec<char> = bs.chars().collect();
assert_eq!(vec!['☃', '\u{FFFD}', '𝞃', '\u{FFFD}', 'a'], chars);

Codepoints can also be iterated over in reverse:

use bstr::B;

let bs = B(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");
let chars: Vec<char> = bs.chars().rev().collect();
assert_eq!(vec!['a', '\u{FFFD}', '𝞃', '\u{FFFD}', '☃'], chars);

Important traits for CharIndices<'a>
pub fn char_indices(&self) -> CharIndices[src]

Returns an iterator over the Unicode scalar values in this byte string along with their starting and ending byte index positions. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

Note that this is slightly different from the CharIndices iterator provided by the standard library. Aside from working on possibly invalid UTF-8, this iterator provides both the corresponding starting and ending byte indices of each codepoint yielded. The ending position is necessary to slice the original byte string when invalid UTF-8 bytes are converted into a Unicode replacement codepoint, since a single replacement codepoint can substitute anywhere from 1 to 3 invalid bytes (inclusive).

Examples

Basic usage:

use bstr::B;

let bs = B(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");
let chars: Vec<(usize, usize, char)> = bs.char_indices().collect();
assert_eq!(chars, vec![
    (0, 3, '☃'),
    (3, 4, '\u{FFFD}'),
    (4, 8, '𝞃'),
    (8, 10, '\u{FFFD}'),
    (10, 11, 'a'),
]);

Codepoints can also be iterated over in reverse:

use bstr::B;

let bs = B(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");
let chars: Vec<(usize, usize, char)> = bs
    .char_indices()
    .rev()
    .collect();
assert_eq!(chars, vec![
    (10, 11, 'a'),
    (8, 10, '\u{FFFD}'),
    (4, 8, '𝞃'),
    (3, 4, '\u{FFFD}'),
    (0, 3, '☃'),
]);

Important traits for Graphemes<'a>
pub fn graphemes(&self) -> Graphemes[src]

Returns an iterator over the grapheme clusters in this byte string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

Examples

This example shows how multiple codepoints can combine to form a single grapheme cluster:

use bstr::B;

let bs = B("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<&str> = bs.graphemes().collect();
assert_eq!(vec!["à̖", "🇺🇸"], graphemes);

This shows that graphemes can be iterated over in reverse:

use bstr::B;

let bs = B("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<&str> = bs.graphemes().rev().collect();
assert_eq!(vec!["🇺🇸", "à̖"], graphemes);

Important traits for GraphemeIndices<'a>
pub fn grapheme_indices(&self) -> GraphemeIndices[src]

Returns an iterator over the grapheme clusters in this byte string along with their starting and ending byte index positions. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

Examples

This example shows how to get the byte offsets of each individual grapheme cluster:

use bstr::B;

let bs = B("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<(usize, usize, &str)> =
    bs.grapheme_indices().collect();
assert_eq!(vec![(0, 5, "à̖"), (5, 13, "🇺🇸")], graphemes);

This example shows what happens when invalid UTF-8 is enountered. Note that the offsets are valid indices into the original string, and do not necessarily correspond to the length of the &str returned!

use bstr::BString;

let mut bytes = BString::new();
bytes.push("a\u{0300}\u{0316}");
bytes.push_byte(b'\xFF');
bytes.push("\u{1F1FA}\u{1F1F8}");

let graphemes: Vec<(usize, usize, &str)> =
    bytes.grapheme_indices().collect();
assert_eq!(
    graphemes,
    vec![(0, 5, "à̖"), (5, 6, "\u{FFFD}"), (6, 14, "🇺🇸")]
);

Important traits for Words<'a>
pub fn words(&self) -> Words[src]

Returns an iterator over the words in this byte string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

This is similar to words_with_breaks, except it only returns elements that contain a "word" character. A word character is defined by UTS #18 (Annex C) to be the combination of the Alphabetic and Join_Control properties, along with the Decimal_Number, Mark and Connector_Punctuation general categories.

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

Basic usage:

use bstr::B;

let bs = B(r#"The quick ("brown") fox can't jump 32.3 feet, right?"#);
let words: Vec<&str> = bs.words().collect();
assert_eq!(words, vec![
    "The", "quick", "brown", "fox", "can't",
    "jump", "32.3", "feet", "right",
]);

Important traits for WordIndices<'a>
pub fn word_indices(&self) -> WordIndices[src]

Returns an iterator over the words in this byte string along with their starting and ending byte index positions.

This is similar to words_with_break_indices, except it only returns elements that contain a "word" character. A word character is defined by UTS #18 (Annex C) to be the combination of the Alphabetic and Join_Control properties, along with the Decimal_Number, Mark and Connector_Punctuation general categories.

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

This example shows how to get the byte offsets of each individual word:

use bstr::B;

let bs = B("can't jump 32.3 feet");
let words: Vec<(usize, usize, &str)> = bs.word_indices().collect();
assert_eq!(words, vec![
    (0, 5, "can't"),
    (6, 10, "jump"),
    (11, 15, "32.3"),
    (16, 20, "feet"),
]);

Important traits for WordsWithBreaks<'a>
pub fn words_with_breaks(&self) -> WordsWithBreaks[src]

Returns an iterator over the words in this byte string, along with all breaks between the words. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

Basic usage:

use bstr::B;

let bs = B(r#"The quick ("brown") fox can't jump 32.3 feet, right?"#);
let words: Vec<&str> = bs.words_with_breaks().collect();
assert_eq!(words, vec![
    "The", " ", "quick", " ", "(", "\"", "brown", "\"", ")",
    " ", "fox", " ", "can't", " ", "jump", " ", "32.3", " ", "feet",
    ",", " ", "right", "?",
]);

Important traits for WordsWithBreakIndices<'a>
pub fn words_with_break_indices(&self) -> WordsWithBreakIndices[src]

Returns an iterator over the words and their byte offsets in this byte string, along with all breaks between the words. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

This example shows how to get the byte offsets of each individual word:

use bstr::B;

let bs = B("can't jump 32.3 feet");
let words: Vec<(usize, usize, &str)> =
    bs.words_with_break_indices().collect();
assert_eq!(words, vec![
    (0, 5, "can't"),
    (5, 6, " "),
    (6, 10, "jump"),
    (10, 11, " "),
    (11, 15, "32.3"),
    (15, 16, " "),
    (16, 20, "feet"),
]);

Important traits for Sentences<'a>
pub fn sentences(&self) -> Sentences[src]

Returns an iterator over the sentences in this byte string.

Typically, a sentence will include its trailing punctuation and whitespace. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since sentences are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

Basic usage:

use bstr::B;

let bs = B("I want this. Not that. Right now.");
let sentences: Vec<&str> = bs.sentences().collect();
assert_eq!(sentences, vec![
    "I want this. ",
    "Not that. ",
    "Right now.",
]);

Important traits for SentenceIndices<'a>
pub fn sentence_indices(&self) -> SentenceIndices[src]

Returns an iterator over the sentences in this byte string along with their starting and ending byte index positions.

Typically, a sentence will include its trailing punctuation and whitespace. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since sentences are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

Examples

Basic usage:

use bstr::B;

let bs = B("I want this. Not that. Right now.");
let sentences: Vec<(usize, usize, &str)> =
    bs.sentence_indices().collect();
assert_eq!(sentences, vec![
    (0, 13, "I want this. "),
    (13, 23, "Not that. "),
    (23, 33, "Right now."),
]);

Important traits for Lines<'a>
pub fn lines(&self) -> Lines[src]

An iterator over all lines in a byte string, without their terminators.

For this iterator, the only line terminators recognized are \r\n and \n.

Examples

Basic usage:

use bstr::{B, BStr};

let s = B("\
foo

bar\r
baz


quux");
let lines: Vec<&BStr> = s.lines().collect();
assert_eq!(lines, vec![
    "foo", "", "bar", "baz", "", "", "quux",
]);

Important traits for LinesWithTerminator<'a>
pub fn lines_with_terminator(&self) -> LinesWithTerminator[src]

An iterator over all lines in a byte string, including their terminators.

For this iterator, the only line terminator recognized is \n. (Since line terminators are included, this also handles \r\n line endings.)

Line terminators are only included if they are present in the original byte string. For example, the last line in a byte string may not end with a line terminator.

Concatenating all elements yielded by this iterator is guaranteed to yield the original byte string.

Examples

Basic usage:

use bstr::{B, BStr};

let s = B("\
foo

bar\r
baz


quux");
let lines: Vec<&BStr> = s.lines_with_terminator().collect();
assert_eq!(lines, vec![
    "foo\n", "\n", "bar\r\n", "baz\n", "\n", "\n", "quux",
]);

pub fn trim(&self) -> &BStr[src]

Return a byte string slice with leading and trailing whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

Examples

Basic usage:

use bstr::B;

let s = B(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim(), "foo\tbar");

pub fn trim_start(&self) -> &BStr[src]

Return a byte string slice with leading whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

Examples

Basic usage:

use bstr::B;

let s = B(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim_start(), "foo\tbar\t\u{2003}\n");

pub fn trim_end(&self) -> &BStr[src]

Return a byte string slice with trailing whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

Examples

Basic usage:

use bstr::B;

let s = B(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim_end(), " foo\tbar");

pub fn trim_with<F: FnMut(char) -> bool>(&self, trim: F) -> &BStr[src]

Return a byte string slice with leading and trailing characters satisfying the given predicate removed.

Examples

Basic usage:

use bstr::B;

let s = B("123foo5bar789");
assert_eq!(s.trim_with(|c| c.is_numeric()), "foo5bar");

pub fn trim_start_with<F: FnMut(char) -> bool>(&self, trim: F) -> &BStr[src]

Return a byte string slice with leading characters satisfying the given predicate removed.

Examples

Basic usage:

use bstr::B;

let s = B("123foo5bar789");
assert_eq!(s.trim_start_with(|c| c.is_numeric()), "foo5bar789");

pub fn trim_end_with<F: FnMut(char) -> bool>(&self, trim: F) -> &BStr[src]

Return a byte string slice with trailing characters satisfying the given predicate removed.

Examples

Basic usage:

use bstr::B;

let s = B("123foo5bar");
assert_eq!(s.trim_end_with(|c| c.is_numeric()), "123foo5bar");

pub fn to_lowercase(&self) -> BString[src]

Returns a new BString containing the lowercase equivalent of this byte string.

In this case, lowercase is defined according to the Lowercase Unicode property.

If invalid UTF-8 is seen, or if a character has no lowercase variant, then it is written to the given buffer unchanged.

Note that some characters in this byte string may expand into multiple characters when changing the case, so the number of bytes written to the given byte string may not be equivalent to the number of bytes in this byte string.

If you'd like to reuse an allocation for performance reasons, then use to_lowercase_into instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("HELLO Β");
assert_eq!("hello β", s.to_lowercase());

Scripts without case are not changed:

use bstr::{B, BString};

let s = B("农历新年");
assert_eq!("农历新年", s.to_lowercase());

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"FOO\xFFBAR\xE2\x98BAZ");
assert_eq!(B(b"foo\xFFbar\xE2\x98baz"), s.to_lowercase());

pub fn to_lowercase_into(&self, buf: &mut BString)[src]

Writes the lowercase equivalent of this byte string into the given buffer. The buffer is not cleared before written to.

In this case, lowercase is defined according to the Lowercase Unicode property.

If invalid UTF-8 is seen, or if a character has no lowercase variant, then it is written to the given buffer unchanged.

Note that some characters in this byte string may expand into multiple characters when changing the case, so the number of bytes written to the given byte string may not be equivalent to the number of bytes in this byte string.

If you don't need to amortize allocation and instead prefer convenience, then use to_lowercase instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("HELLO Β");

let mut buf = BString::new();
s.to_lowercase_into(&mut buf);
assert_eq!("hello β", buf);

Scripts without case are not changed:

use bstr::{B, BString};

let s = B("农历新年");

let mut buf = BString::new();
s.to_lowercase_into(&mut buf);
assert_eq!("农历新年", buf);

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"FOO\xFFBAR\xE2\x98BAZ");

let mut buf = BString::new();
s.to_lowercase_into(&mut buf);
assert_eq!(B(b"foo\xFFbar\xE2\x98baz"), buf);

pub fn to_ascii_lowercase(&self) -> BString[src]

Returns a new BString containing the ASCII lowercase equivalent of this byte string.

In this case, lowercase is only defined in ASCII letters. Namely, the letters A-Z are converted to a-z. All other bytes remain unchanged. In particular, the length of the byte string returned is always equivalent to the length of this byte string.

If you'd like to reuse an allocation for performance reasons, then use make_ascii_lowercase to perform the conversion in place.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("HELLO Β");
assert_eq!("hello Β", s.to_ascii_lowercase());

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"FOO\xFFBAR\xE2\x98BAZ");
assert_eq!(B(b"foo\xFFbar\xE2\x98baz"), s.to_ascii_lowercase());

pub fn make_ascii_lowercase(&mut self)[src]

Convert this byte string to its lowercase ASCII equivalent in place.

In this case, lowercase is only defined in ASCII letters. Namely, the letters A-Z are converted to a-z. All other bytes remain unchanged.

If you don't need to do the conversion in place and instead prefer convenience, then use to_ascii_lowercase instead.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("HELLO Β");
s.make_ascii_lowercase();
assert_eq!("hello Β", s);

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let mut s = BString::from_slice(b"FOO\xFFBAR\xE2\x98BAZ");
s.make_ascii_lowercase();
assert_eq!(B(b"foo\xFFbar\xE2\x98baz"), s);

pub fn to_uppercase(&self) -> BString[src]

Returns a new BString containing the uppercase equivalent of this byte string.

In this case, uppercase is defined according to the Uppercase Unicode property.

If invalid UTF-8 is seen, or if a character has no uppercase variant, then it is written to the given buffer unchanged.

Note that some characters in this byte string may expand into multiple characters when changing the case, so the number of bytes written to the given byte string may not be equivalent to the number of bytes in this byte string.

If you'd like to reuse an allocation for performance reasons, then use to_uppercase_into instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("hello β");
assert_eq!("HELLO Β", s.to_uppercase());

Scripts without case are not changed:

use bstr::{B, BString};

let s = B("农历新年");
assert_eq!("农历新年", s.to_uppercase());

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"foo\xFFbar\xE2\x98baz");
assert_eq!(B(b"FOO\xFFBAR\xE2\x98BAZ"), s.to_uppercase());

pub fn to_uppercase_into(&self, buf: &mut BString)[src]

Writes the uppercase equivalent of this byte string into the given buffer. The buffer is not cleared before written to.

In this case, uppercase is defined according to the Uppercase Unicode property.

If invalid UTF-8 is seen, or if a character has no uppercase variant, then it is written to the given buffer unchanged.

Note that some characters in this byte string may expand into multiple characters when changing the case, so the number of bytes written to the given byte string may not be equivalent to the number of bytes in this byte string.

If you don't need to amortize allocation and instead prefer convenience, then use to_uppercase instead.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("hello β");

let mut buf = BString::new();
s.to_uppercase_into(&mut buf);
assert_eq!("HELLO Β", buf);

Scripts without case are not changed:

use bstr::{B, BString};

let s = B("农历新年");

let mut buf = BString::new();
s.to_uppercase_into(&mut buf);
assert_eq!("农历新年", buf);

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"foo\xFFbar\xE2\x98baz");

let mut buf = BString::new();
s.to_uppercase_into(&mut buf);
assert_eq!(B(b"FOO\xFFBAR\xE2\x98BAZ"), buf);

pub fn to_ascii_uppercase(&self) -> BString[src]

Returns a new BString containing the ASCII uppercase equivalent of this byte string.

In this case, uppercase is only defined in ASCII letters. Namely, the letters a-z are converted to A-Z. All other bytes remain unchanged. In particular, the length of the byte string returned is always equivalent to the length of this byte string.

If you'd like to reuse an allocation for performance reasons, then use make_ascii_uppercase to perform the conversion in place.

Examples

Basic usage:

use bstr::{B, BString};

let s = B("hello β");
assert_eq!("HELLO β", s.to_ascii_uppercase());

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let s = B(b"foo\xFFbar\xE2\x98baz");
assert_eq!(B(b"FOO\xFFBAR\xE2\x98BAZ"), s.to_ascii_uppercase());

pub fn make_ascii_uppercase(&mut self)[src]

Convert this byte string to its uppercase ASCII equivalent in place.

In this case, uppercase is only defined in ASCII letters. Namely, the letters a-z are converted to A-Z. All other bytes remain unchanged.

If you don't need to do the conversion in place and instead prefer convenience, then use to_ascii_uppercase instead.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("hello β");
s.make_ascii_uppercase();
assert_eq!("HELLO β", s);

Invalid UTF-8 remains as is:

use bstr::{B, BString};

let mut s = BString::from_slice(b"foo\xFFbar\xE2\x98baz");
s.make_ascii_uppercase();
assert_eq!(B(b"FOO\xFFBAR\xE2\x98BAZ"), s);

pub fn reverse_bytes(&mut self)[src]

Reverse the bytes in this string, in place.

Note that this is not necessarily a well formed operation. For example, if this byte string contains valid UTF-8 that isn't ASCII, then reversing the string will likely result in invalid UTF-8 and otherwise non-sensical content.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("hello");
s.reverse_bytes();
assert_eq!(s, "olleh");

pub fn reverse_chars(&mut self)[src]

Reverse the codepoints in this string, in place.

If this byte string is valid UTF-8, then its reversal by codepoint is also guaranteed to be valid UTF-8.

This operation is equivalent to the following, but without allocating:

use bstr::BString;

let mut s = BString::from("foo☃bar");

let mut chars: Vec<char> = s.chars().collect();
chars.reverse();

let reversed: String = chars.into_iter().collect();
assert_eq!(reversed, "rab☃oof");

Note that this is not necessarily a well formed operation. For example, if this byte string contains grapheme clusters with more than one codepoint, then those grapheme clusters will not necessarily be preserved. If you'd like to preserve grapheme clusters, then use reverse_graphemes instead.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("foo☃bar");
s.reverse_chars();
assert_eq!(s, "rab☃oof");

This example shows that not all reversals lead to a well formed string. For example, in this case, combining marks are used to put accents over some letters, and those accent marks must appear after the codepoints they modify.

use bstr::{B, BString};

let mut s = BString::from("résumé");
s.reverse_chars();
assert_eq!(s, B(b"\xCC\x81emus\xCC\x81er"));

A word of warning: the above example relies on the fact that résumé is in decomposed normal form, which means there are separate codepoints for the accents above e. If it is instead in composed normal form, then the example works:

use bstr::{B, BString};

let mut s = BString::from("résumé");
s.reverse_chars();
assert_eq!(s, "émusér");

The point here is to be cautious and not assume that just because reverse_chars works in one case, that it therefore works in all cases.

pub fn reverse_graphemes(&mut self)[src]

Reverse the graphemes in this string, in place.

If this byte string is valid UTF-8, then its reversal by grapheme is also guaranteed to be valid UTF-8.

This operation is equivalent to the following, but without allocating:

use bstr::BString;

let mut s = BString::from("foo☃bar");

let mut graphemes: Vec<&str> = s.graphemes().collect();
graphemes.reverse();

let reversed = graphemes.concat();
assert_eq!(reversed, "rab☃oof");

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("foo☃bar");
s.reverse_graphemes();
assert_eq!(s, "rab☃oof");

This example shows how this correctly handles grapheme clusters, unlike reverse_chars.

use bstr::BString;

let mut s = BString::from("résumé");
s.reverse_graphemes();
assert_eq!(s, "émusér");

pub fn is_ascii(&self) -> bool[src]

Returns true if and only if every byte in this byte string is ASCII.

ASCII is an encoding that defines 128 codepoints. A byte corresponds to an ASCII codepoint if and only if it is in the inclusive range [0, 127].

Examples

Basic usage:

use bstr::B;

assert!(B("abc").is_ascii());
assert!(!B("☃βツ").is_ascii());
assert!(!B(b"\xFF").is_ascii());

pub fn is_utf8(&self) -> bool[src]

Returns true if and only if the entire byte string is valid UTF-8.

If you need location information about where a byte string's first invalid UTF-8 byte is, then use the to_str method.

Examples

Basic usage:

use bstr::B;

assert!(B("abc").is_utf8());
assert!(B("☃βツ").is_utf8());
// invalid bytes
assert!(!B(b"abc\xFF").is_utf8());
// surrogate encoding
assert!(!B(b"\xED\xA0\x80").is_utf8());
// incomplete sequence
assert!(!B(b"\xF0\x9D\x9Ca").is_utf8());
// overlong sequence
assert!(!B(b"\xF0\x82\x82\xAC").is_utf8());

pub fn split_at(&self, at: usize) -> (&BStr, &BStr)[src]

Divides this byte string into two at an index.

The first byte string will contain all bytes at indices [0, at), and the second byte string will contain all bytes at indices [at, len).

Panics

Panics if at > len.

Examples

Basic usage:

use bstr::B;

assert_eq!(B("foobar").split_at(3), (B("foo"), B("bar")));
assert_eq!(B("foobar").split_at(0), (B(""), B("foobar")));
assert_eq!(B("foobar").split_at(6), (B("foobar"), B("")));

pub fn split_at_mut(&mut self, at: usize) -> (&mut BStr, &mut BStr)[src]

Divides this mutable byte string into two at an index.

The first byte string will contain all bytes at indices [0, at), and the second byte string will contain all bytes at indices [at, len).

Panics

Panics if at > len.

Examples

Basic usage:

use bstr::{B, BString};

let mut b = BString::from("foobar");
{
    let (left, right) = b.split_at_mut(3);
    left[2] = b'z';
    right[2] = b'z';
}
assert_eq!(b, B("fozbaz"));

pub fn get<I: SliceIndex>(&self, at: I) -> Option<&I::Output>[src]

Retrieve a reference to a byte or a subslice, depending on the type of the index given.

If given a position, this returns a reference to the byte at that position, if it exists.

If given a range, this returns the slice of bytes corresponding to that range in this byte string.

In the case of invalid indices, this returns None.

Examples

Basic usage:

use bstr::B;

let s = B("baz");
assert_eq!(s.get(1), Some(&b'a'));
assert_eq!(s.get(0..2), Some(B("ba")));
assert_eq!(s.get(2..), Some(B("z")));
assert_eq!(s.get(1..=2), Some(B("az")));

pub fn get_mut<I: SliceIndex>(&mut self, at: I) -> Option<&mut I::Output>[src]

Retrieve a mutable reference to a byte or a subslice, depending on the type of the index given.

If given a position, this returns a reference to the byte at that position, if it exists.

If given a range, this returns the slice of bytes corresponding to that range in this byte string.

In the case of invalid indices, this returns None.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("baz");
if let Some(mut slice) = s.get_mut(1..) {
    slice[0] = b'o';
    slice[1] = b'p';
}
assert_eq!(s, "bop");

pub unsafe fn get_unchecked<I: SliceIndex>(&self, at: I) -> &I::Output[src]

Retrieve a reference to a byte or a subslice, depending on the type of the index given, while explicitly eliding bounds checks.

If given a position, this returns a reference to the byte at that position, if it exists.

If given a range, this returns the slice of bytes corresponding to that range in this byte string.

In the case of invalid indices, this returns None.

Safety

Callers must ensure that the supplied bounds are correct. If they are out of bounds, then this results in undefined behavior. For a safe alternative, use get.

Examples

Basic usage:

use bstr::B;

let s = B("baz");
unsafe {
    assert_eq!(s.get_unchecked(1), &b'a');
    assert_eq!(s.get_unchecked(0..2), "ba");
    assert_eq!(s.get_unchecked(2..), "z");
    assert_eq!(s.get_unchecked(1..=2), "az");
}

pub unsafe fn get_unchecked_mut<I: SliceIndex>(
    &mut self,
    at: I
) -> &mut I::Output
[src]

Retrieve a mutable reference to a byte or a subslice, depending on the type of the index given, while explicitly eliding bounds checks.

If given a position, this returns a reference to the byte at that position, if it exists.

If given a range, this returns the slice of bytes corresponding to that range in this byte string.

In the case of invalid indices, this returns None.

Safety

Callers must ensure that the supplied bounds are correct. If they are out of bounds, then this results in undefined behavior. For a safe alternative, use get_mut.

Examples

Basic usage:

use bstr::BString;

let mut s = BString::from("baz");
{
    let mut slice = unsafe { s.get_unchecked_mut(1..) };
    slice[0] = b'o';
    slice[1] = b'p';
}
assert_eq!(s, "bop");

pub fn last(&self) -> Option<u8>[src]

Returns the last byte in this byte string, if it's non-empty. If this byte string is empty, this returns None.

Examples

Basic usage:

use bstr::B;

assert_eq!(Some(b'z'), B("baz").last());
assert_eq!(None, B("").last());

pub fn copy_within<R>(&mut self, src: R, dest: usize) where
    R: RangeBounds<usize>, 
[src]

Copies elements from one part of the slice to another part of itself, where the parts may be overlapping.

src is the range within this byte string to copy from, while dest is the starting index of the range within this byte string to copy to. The length indicated by src must be less than or equal to the number of bytes from dest to the end of the byte string.

Panics

Panics if either range is out of bounds, or if src is too big to fit into dest, or if the end of src is before the start.

Examples

Copying four bytes within a byte string:

use bstr::BStr;

let mut buf = *b"Hello, World!";
let s = BStr::new_mut(&mut buf);
s.copy_within(1..5, 8);
assert_eq!(s, "Hello, Wello!");

pub fn as_ptr(&self) -> *const u8[src]

Returns a raw pointer to this byte string's underlying bytes.

Safety

The caller must ensure that the byte string outlives the pointer this function returns, or else it will end up pointing to garbage.

Modifying the container (like a BString) referenced by this byte string may cause its buffer to be reallocated, which would also make any pointers to it invalid.

Examples

Basic usage:

use bstr::B;

let s = B("hello");
let p = s.as_ptr();

unsafe {
    assert_eq!(*p.add(2), b'l');
}

pub fn as_mut_ptr(&mut self) -> *mut u8[src]

Returns a raw mutable pointer to this byte string's underlying bytes.

Safety

The caller must ensure that the byte string outlives the pointer this function returns, or else it will end up pointing to garbage.

Modifying the container (like a BString) referenced by this byte string may cause its buffer to be reallocated, which would also make any pointers to it invalid.

Examples

Basic usage:

use bstr::BStr;

let mut buf = &mut [b'h', b'e', b'l', b'l', b'o'];
let mut s = BStr::new_mut(buf);
let p = s.as_mut_ptr();

unsafe {
    *p.add(2) = b'Z';
}
assert_eq!("heZlo", s);

Trait Implementations

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl PartialEq<BStr> for BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<&'a [u8]> for BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<BStr> for &'a [u8][src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<Vec<u8>> for BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<BStr> for Vec<u8>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<Vec<u8>> for &'a BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<&'a BStr> for Vec<u8>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<Cow<'a, BStr>> for &'a BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<&'a BStr> for Cow<'a, BStr>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<Cow<'a, [u8]>> for &'a BStr[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a, 'b> PartialEq<&'a BStr> for Cow<'a, [u8]>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl AsRef<BStr> for BString[src]

impl AsRef<[u8]> for BStr[src]

impl AsRef<BStr> for [u8][src]

impl AsRef<BStr> for str[src]

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

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

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

impl<'a> From<&'a BStr> for Cow<'a, BStr>[src]

impl ToOwned for BStr[src]

type Owned = BString

The resulting type after obtaining ownership.

fn clone_into(&self, target: &mut Self::Owned)[src]

🔬 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 Ord for BStr[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

impl Eq for BStr[src]

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<&'a BStr> for BString[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BString> for &'a BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl PartialOrd<BStr> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<[u8]> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for [u8][src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<&'a [u8]> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for &'a [u8][src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<str> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for str[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<&'a str> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for &'a str[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<Vec<u8>> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for Vec<u8>[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<Vec<u8>> for &'a BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<&'a BStr> for Vec<u8>[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<String> for BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<BStr> for String[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<String> for &'a BStr[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<'a, 'b> PartialOrd<&'a BStr> for String[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl AsMut<BStr> for BString[src]

impl AsMut<[u8]> for BStr[src]

impl AsMut<BStr> for [u8][src]

impl Debug for BStr[src]

impl Display for BStr[src]

impl Index<usize> for BStr[src]

type Output = u8

The returned type after indexing.

impl Index<RangeFull> for BStr[src]

type Output = BStr

The returned type after indexing.

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

type Output = BStr

The returned type after indexing.

impl Index<RangeInclusive<usize>> for BStr[src]

type Output = BStr

The returned type after indexing.

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

type Output = BStr

The returned type after indexing.

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

type Output = BStr

The returned type after indexing.

impl Index<RangeToInclusive<usize>> for BStr[src]

type Output = BStr

The returned type after indexing.

impl IndexMut<usize> for BStr[src]

impl IndexMut<RangeFull> for BStr[src]

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

impl IndexMut<RangeInclusive<usize>> for BStr[src]

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

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

impl IndexMut<RangeToInclusive<usize>> for BStr[src]

impl Hash for BStr[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

impl<'a> FromIterator<&'a BStr> for BString[src]

impl Borrow<BStr> for BString[src]

Auto Trait Implementations

impl Send for BStr

impl Sync for BStr

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]