Struct NodeBuilder

Source
pub struct NodeBuilder<T> { /* private fields */ }

Implementations§

Source§

impl<T> NodeBuilder<T>
where T: Serialize + DeserializeOwned + 'static,

Source

pub fn election_timeout(self, ms: u32) -> Self

Set the election timeout in milliseconds. This is discouraged, as the timeout should be randomized (so that nodes are less likely to simultaneously initiate elections). See eleciton_timeout_range

NB: If election_timeout_range is also set, this will overwrite it.

Defaults to a random value in the range (150, 300)

Source

pub fn election_timeout_range(self, low_ms: u32, high_ms: u32) -> Self

Set the range for the randomized value of the election timeout.

Defaults to (150, 300).

Source

pub fn heartbeat_timeout(self, ms: u32) -> Self

Set the leader heartbeat interval in milliseconds

Defaults to 50

Source

pub fn id(self, id: u32) -> Self

Set the node’s id.

Defaults to a random number

Source

pub fn channel(self, name: &str) -> Self

Set the name of the BroadcastChannel the node should connect to

Defaults to "raft-nodes"

Source

pub fn on_received<F>(self, callback: F) -> Self
where F: Fn(T) + 'static,

Attach a closure to the node that will be called when the node receives a [Message::Payload] message

Source

pub fn on_role_change<F>(self, callback: F) -> Self
where F: Fn(Role) + 'static,

Attach a closure to the node that will be called when the node’s role is changed.

Source

pub fn build(self) -> Arc<Node<T>>

Finalize the builder and construct a Node

Trait Implementations§

Source§

impl<T> Default for NodeBuilder<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for NodeBuilder<T>

§

impl<T> !RefUnwindSafe for NodeBuilder<T>

§

impl<T> !Send for NodeBuilder<T>

§

impl<T> !Sync for NodeBuilder<T>

§

impl<T> Unpin for NodeBuilder<T>

§

impl<T> !UnwindSafe for NodeBuilder<T>

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