Module digest_hash::personality [−][src]
Helper functions for hashing data in a specific representation.
The Hash
trait implementations provided by this crate do not cover
machine-dependent data types, or types for which data representation
for calculating a digest is subject to implementer's choice.
This module defines helper functions that provide an explicit,
auditable way to select some commonly used representation choices.
Examples
The recommended way to use the hash personality helper functions is to
list them in use
statements at the beginning of the module that provides
Hash
implementations using the functions. For convenience, the functions
can be given short local names.
use digest_hash::personality::hash_bool_as_byte as hash_bool; use digest_hash::personality::hash_ip_addr_as_ipv6_in_network_order as hash_ip_addr; use digest_hash::{Hash, EndianInput}; use std::net::IpAddr; pub struct A { addr: IpAddr, foo: bool } impl Hash for A { fn hash<H>(&self, digest: &mut H) where H: EndianInput { hash_ip_addr(self.addr, digest); hash_bool(self.foo, digest); } }
Functions
hash_bool_as_byte |
Feeds a boolean value as a byte to the digest function. |
hash_char_as_utf8 |
Feeds a Unicode character, encoded in UTF-8, to the digest function. |
hash_char_as_utf16 |
Feeds a Unicode character, encoded in UTF-16, to the digest function. |
hash_char_as_utf32 |
Feeds a Unicode character, encoded in UTF-32, to the digest function. |
hash_ip_addr_as_ipv6_in_network_order |
Feeds an IP address, canonicalized as an IPv6 address, in the network byte order to the digest function. |
hash_ipv4_addr_in_network_order |
Feeds an IPv4 address in the network byte order to the digest function. |
hash_ipv6_addr_in_network_order |
Feeds an IPv6 address in the network byte order to the digest function. |
hash_slice_as_elements |
Computes the digest over a slice by feeding the slice's elements in the direct order to the digest function. |
hash_str_as_utf16 |
Encodes a string in UTF-16 and feeds it to the digest function. |
hash_str_as_utf16_with_bom |
Encodes a string in UTF-16, prepended with a Byte Order Mark (U+FEFF) code point, and feeds it to the digest function. |