Trait BytesExt

Source
pub trait BytesExt {
    // Required method
    fn matches_special_lowercase<B: AsRef<[u8]>>(self, other: B) -> bool;
}
Expand description

Extended functionality for &[u8].

Required Methods§

Source

fn matches_special_lowercase<B: AsRef<[u8]>>(self, other: B) -> bool

Returns whether self matches case-insensitively to other, which only contains ASCII characters with the 0b100000 (lowercase) bit set.

This method can often be used in place of eq_ignore_ascii_case and is more performant since this uses a simple bitwise OR instead of a lookup table. The main restriction is that only the following ASCII characters may be in other:

TypeValues
Alphanumerica-z, 0-9
Punctuation!, ?, ., ,, :, ;, ', `, \, /, #, $, &, |, ~
Brackets<, >, (, ), {, }
Math+, -, *, %, =
Non-GraphicalSPACE, DELETE
§Examples

This method can be used to match against filesystem paths:

use oceanpkg_shared::ext::BytesExt;

let lower = b"../hello.txt";
let upper = b"../HELLO.TXT";

assert!(upper.matches_special_lowercase(lower));
assert!(lower.matches_special_lowercase(lower));
assert!(!lower.matches_special_lowercase(upper));
assert!(!upper.matches_special_lowercase(upper));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl BytesExt for &[u8]

Source§

fn matches_special_lowercase<B: AsRef<[u8]>>(self, other: B) -> bool

Implementors§