HashRing

Struct HashRing 

Source
pub struct HashRing<T: Clone, S = RandomState> { /* private fields */ }
Expand description

A concurrent, consistent hash ring.

Provides the following features:

  • Lookup optimized ring storage.
  • Key overrides that allow you to pin a key to a specific node.

Implementations§

Source§

impl<T> HashRing<T>
where T: Clone,

Source

pub fn new() -> Self

Constructs a new instance of HashRing.

Source

pub fn add_node<K: Hash>(&self, key: K, node: T) -> Option<T>

Adds a node to the existing set of nodes in the ring, this will replace an entry if one exists.

Source

pub fn remove_node<K: Hash>(&self, key: K) -> Option<T>

Removes a node from the existing set of nodes.

Source

pub fn add_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)

Adds a collection of nodes to the existing set of nodes in the ring, replacing any existing entries if they exist.

Source

pub fn set_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)

Replaces the nodes in the ring with a new set of nodes.

Source

pub fn find_node<K: Hash>(&self, key: K) -> Option<T>

Returns the node responsible for key. If there are no nodes in the ring, it will return None.

Source

pub fn map_node<K: Hash, F: FnMut(Option<&T>)>(&self, key: K, map: F)

Finds the node responsible for the given key and passes it to map.

Source

pub fn add_override<K: Hash>(&self, key: K, node: T) -> Option<T>

Adds an override to the ring.

Source

pub fn add_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>( &self, overrides: I, )

Adds a collection of overrides to the ring.

Source

pub fn set_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>( &self, overrides: I, )

Replaces the overrides in the ring with a new set of overrides.

Source

pub fn remove_override<K: Hash>(&self, key: K) -> Option<T>

Removes an existing override from the ring.

Source

pub fn clear(&self)

Clears all of the nodes and overrides from the hash ring.

Trait Implementations§

Source§

impl<T> Default for HashRing<T>
where T: Clone,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T, S = RandomState> !Freeze for HashRing<T, S>

§

impl<T, S = RandomState> !RefUnwindSafe for HashRing<T, S>

§

impl<T, S> Send for HashRing<T, S>
where S: Send, T: Sync + Send,

§

impl<T, S> Sync for HashRing<T, S>
where S: Sync, T: Sync + Send,

§

impl<T, S> Unpin for HashRing<T, S>
where S: Unpin,

§

impl<T, S> UnwindSafe for HashRing<T, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more