Struct Ring

Source
pub struct Ring { /* private fields */ }

Implementations§

Source§

impl Ring

Source

pub fn new(config: Config) -> Self

Examples found in repository?
examples/ring.rs (line 4)
3fn main() {
4    let mut r = Ring::new(Config::default());
5
6    r.add("1.1.1.1");
7    r.add("2.2.2.2");
8    r.add("3.3.3.3");
9
10    println!("{:?}", r.get("1.1.1.1"));
11    println!("{:?}", r.get("8.8.8.8"));
12    println!("{:?}", r.get("/foo"));
13    println!("{:?}", r.get("/bar"));
14}
Source

pub fn replication_factor(&self) -> u64

Source

pub fn add(&mut self, hostname: &str)

Adds a new host to the ring. If the host already added, ignore.

Examples found in repository?
examples/ring.rs (line 6)
3fn main() {
4    let mut r = Ring::new(Config::default());
5
6    r.add("1.1.1.1");
7    r.add("2.2.2.2");
8    r.add("3.3.3.3");
9
10    println!("{:?}", r.get("1.1.1.1"));
11    println!("{:?}", r.get("8.8.8.8"));
12    println!("{:?}", r.get("/foo"));
13    println!("{:?}", r.get("/bar"));
14}
Source

pub fn remove(&mut self, hostname: &str)

Removes host from the ring.

Source

pub fn get(&mut self, key: &str) -> Option<String>

Locates a host for the key.

Examples found in repository?
examples/ring.rs (line 10)
3fn main() {
4    let mut r = Ring::new(Config::default());
5
6    r.add("1.1.1.1");
7    r.add("2.2.2.2");
8    r.add("3.3.3.3");
9
10    println!("{:?}", r.get("1.1.1.1"));
11    println!("{:?}", r.get("8.8.8.8"));
12    println!("{:?}", r.get("/foo"));
13    println!("{:?}", r.get("/bar"));
14}
Source

pub fn get_least(&mut self, key: &str) -> Option<String>

Picks the least load host for the key.

Source

pub fn hosts(&mut self) -> Vec<String>

Lists all hosts in the ring.

Source

pub fn set_load(&mut self, hostname: &str, load: u64)

Sets the load of host to the given value.

Source

pub fn inc_load(&mut self, hostname: &str)

Increments the load of host by 1.

Source

pub fn decr_load(&mut self, hostname: &str)

Decrements the load of host by 1.

Source

pub fn avg_load(&self) -> f64

Gets the average load of ring.

Trait Implementations§

Auto Trait Implementations§

§

impl Freeze for Ring

§

impl !RefUnwindSafe for Ring

§

impl Unpin for Ring

§

impl !UnwindSafe for Ring

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