Skip to main content

CompareBytes

Trait CompareBytes 

Source
pub trait CompareBytes {
    // Required methods
    fn eq(&self, left: &[u8], right: &[u8]) -> bool;
    fn hash<H: Hasher>(&self, text: &[u8], state: &mut H);
}
Expand description

Compares byte sequences based on a certain equivalence property.

This isn’t a newtype Wrapper<'a>(&'a [u8]) but an external comparison object for the following reasons:

a. If it were newtype, a generic wrap function would be needed. It couldn’t be expressed as a simple closure: for<'a> Fn(&'a [u8]) -> ???<'a> b. Dynamic comparison object can be implemented intuitively. For example, pattern: &Regex would have to be copied to all newtype instances if it were newtype. c. Hash values can be cached if hashing is controlled externally.

Required Methods§

Source

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

Returns true if left and right are equivalent.

Source

fn hash<H: Hasher>(&self, text: &[u8], state: &mut H)

Generates hash which respects the following property: eq(left, right) => hash(left) == hash(right)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<C: CompareBytes + ?Sized> CompareBytes for &C

Source§

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

Source§

fn hash<H: Hasher>(&self, text: &[u8], state: &mut H)

Implementors§