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§
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.