pub struct Chart<const N: usize, T: Debug + Clone + Serialize> { /* private fields */ }
Expand description

The chart keeping track of the discoverd nodes. That a node appears in the chart is no guarentee that it is reachable at this moment.

Implementations

Returns an vector with each discovered node’s socketadresses.

Note
let chart = ChartBuilder::new()
    .with_id(1)
    .with_service_ports([8042, 8043, 8044])
    .finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let port_lists = chart.addr_lists_vec();

Returns a vector over each discoverd node’s nth-socketadress

Note
Examples
let web_server_port = 8043;
let chart = ChartBuilder::new()
    .with_id(1)
    .with_service_ports([8042, web_server_port, 8044])
    .finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let web_server_ports = chart.nth_addr_vec::<2>();

Returns a vector over each discoverd nodes’s socketadress

Note
let chart = ChartBuilder::new()
    .with_id(1)
    .with_service_port(8042)
    .finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let ports = chart.addr_vec();

The array of ports set for this chart instance, set in ChartBuilder::with_service_ports.

The port set for this chart instance, set in ChartBuilder::with_service_port.

The msg struct for this chart instance, set in ChartBuilder::custom_msg.

Wait for new discoveries. Use one of the methods on the notify object to await a new discovery and get the data.

Examples
let chart = ChartBuilder::new()
    .with_id(1)
    .with_service_port(8042)
    .local_discovery(true)
    .finish()?;
let mut node_discoverd = chart.notify();
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever

while chart.size() < full_size as usize {
    let new = node_discoverd.recv().await.unwrap();
    println!("discoverd new node: {:?}", new);
}

number of instances discoverd including self

The id set for this chart instance

The port this instance is using for discovery

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

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

Returns the argument unchanged.

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

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

Calls U::from(self).

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

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)

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.

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

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