Struct anchorhash::Builder [−][src]
pub struct Builder<R, B> where
B: BuildHasher, { /* fields omitted */ }
Expand description
Initialise a new AnchorHash
instance.
An AnchorHash instance can be pre-populated with some set of resources using
with_resources
:
// Anything can be used as the resource! // // Here &str instances are used, but SockAddr instances, structs, Strings, // or anything that makes sense for you can be used too. let backend_servers = vec![ "cache1.itsallbroken.com", "cache2.itsallbroken.com", "cache3.itsallbroken.com", ]; let anchor = anchorhash::Builder::default() .with_resources(backend_servers) .build(100); // In this example, strings are used as keys but anything that implements // std::hash::Hash can be used. let example_user_email = "dom@itsallbroken.com".to_string(); // Get a backend for this user let backend = anchor.get_resource(example_user_email).unwrap(); println!("user mapped to: {}", backend);
By default, a builder constructs an empty AnchorHash, using the
DefaultHasher
. A DefaultHasher
is unlikely to be the fastest option
and therefore the hash implementation can be specified by the user with
with_hasher
:
use fnv::FnvBuildHasher; // Use the Fowler–Noll–Vo hash function - fantastic at very small keys, but // there are better algorithms for larger keys! let mut anchor = anchorhash::Builder::with_hasher(FnvBuildHasher::default()).build(50);
Implementations
Initialise the AnchroHash
instance with support for up to capacity
number of resources.
Panics
This method panics if the number of resources given to
with_resources
exceeds capacity
.
Use the provided hash algorithm when hashing keys.
Construct the AnchorHash
with an initial set of resources.
Trait Implementations
Auto Trait Implementations
impl<R, B> RefUnwindSafe for Builder<R, B> where
B: RefUnwindSafe,
R: RefUnwindSafe,
impl<R, B> UnwindSafe for Builder<R, B> where
B: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more