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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Initialise an empty AnchorHash instance using the DefaultHasher and no pre-populated resources.

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.