Struct instance_chart::Chart
source · [−]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
sourceimpl<const N: usize> Chart<N, u16>
impl<const N: usize> Chart<N, u16>
sourcepub fn addr_lists_vec(&self) -> Vec<(Id, [SocketAddr; N])>
pub fn addr_lists_vec(&self) -> Vec<(Id, [SocketAddr; N])>
Returns an vector with each discovered node’s socketadresses.
Note
- vector order is random
- only availible for Chart configured with
ChartBuilder::with_service_portsand build usingChartBuilder::finish.
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();sourceimpl<const N: usize> Chart<N, u16>
impl<const N: usize> Chart<N, u16>
sourcepub fn nth_addr_vec<const IDX: usize>(&self) -> Vec<(Id, SocketAddr)>
pub fn nth_addr_vec<const IDX: usize>(&self) -> Vec<(Id, SocketAddr)>
Returns a vector over each discoverd node’s nth-socketadress
Note
- vector order is random
- only availible for Chart configured with
ChartBuilder::with_service_portsand build usingChartBuilder::finish.
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>();sourceimpl<'a> Chart<1, u16>
impl<'a> Chart<1, u16>
sourcepub fn addr_vec(&'a self) -> Vec<(Id, SocketAddr)>
pub fn addr_vec(&'a self) -> Vec<(Id, SocketAddr)>
Returns a vector over each discoverd nodes’s socketadress
Note
- vector order is random
- only availible for Chart configured with
ChartBuilder::with_service_portand build usingChartBuilder::finish.
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();sourceimpl<const N: usize> Chart<N, u16>
impl<const N: usize> Chart<N, u16>
sourcepub fn get_addr_list(&self, id: Id) -> Option<[SocketAddr; N]>
pub fn get_addr_list(&self, id: Id) -> Option<[SocketAddr; N]>
Get all the SocketAddr’s for a given node’s Id
Note
returns None if the node was not in the Chart
Performance
This locks the map. if you need adresses for many nodes
is faster to get a vector of them at once Self::addr_lists_vec()
instead of calling this repeatedly
Panics
This function panics when called with the Id of the chart instance
it is called on
Examples
let service_ports = [8042, 8043, 8044];
let chart = ChartBuilder::new()
.with_id(1)
.with_service_ports(service_ports)
.finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let from_chart = chart.get_addr_list(2);
assert_eq!(None, from_chart);sourceimpl<const N: usize> Chart<N, u16>
impl<const N: usize> Chart<N, u16>
sourcepub fn get_nth_addr<const IDX: usize>(&self, id: Id) -> Option<SocketAddr>
pub fn get_nth_addr<const IDX: usize>(&self, id: Id) -> Option<SocketAddr>
Get a nodes nth SocketAddr’s given its Id
Note
returns None if the node was not in the Chart
Panics
This function panics when called with the Id of the chart instance
it is called on
Performance
This locks the map. if you need adresses for many nodes
is faster to get a vector of them at once Self::addr_lists_vec()
instead of calling this repeatedly
Examples
let port = 8043;
let chart = ChartBuilder::new()
.with_id(1)
.with_service_ports([8042, port, 8044])
.finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let from_chart = chart.get_nth_addr::<2>(2);
assert_eq!(None, from_chart);sourceimpl<'a> Chart<1, u16>
impl<'a> Chart<1, u16>
sourcepub fn get_addr(&self, id: Id) -> Option<SocketAddr>
pub fn get_addr(&self, id: Id) -> Option<SocketAddr>
Get a nodes SocketAddr’s given its Id
Note
returns None if the node was not in the Chart
Panics
This function panics when called with the Id of the chart instance
it is called on
Performance
This locks the map. if you need adresses for many nodes
is faster to get a vector of them at once Self::addr_lists_vec()
instead of calling this repeatedly
Examples
let port = 8043;
let chart = ChartBuilder::new()
.with_id(1)
.with_service_ports([port])
.finish()?;
let maintain = discovery::maintain(chart.clone());
let _ = tokio::spawn(maintain); // maintain task will run forever
let from_chart = chart.get_addr(2);
assert_eq!(None, from_chart);sourceimpl<const N: usize> Chart<N, u16>
impl<const N: usize> Chart<N, u16>
The array of ports set for this chart instance, set in ChartBuilder::with_service_ports.
pub fn our_service_ports(&self) -> &[u16]
sourceimpl Chart<1, u16>
impl Chart<1, u16>
The port set for this chart instance, set in ChartBuilder::with_service_port.
pub fn our_service_port(&self) -> u16
sourceimpl<T: Debug + Clone + Serialize> Chart<1, T>
impl<T: Debug + Clone + Serialize> Chart<1, T>
The msg struct for this chart instance, set in ChartBuilder::custom_msg.
sourceimpl<const N: usize, T: Debug + Clone + Serialize + DeserializeOwned> Chart<N, T>
impl<const N: usize, T: Debug + Clone + Serialize + DeserializeOwned> Chart<N, T>
sourcepub fn notify(&self) -> Notify<N, T>
pub fn notify(&self) -> Notify<N, T>
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);
}
sourcepub fn discovery_port(&self) -> u16
pub fn discovery_port(&self) -> u16
The port this instance is using for discovery
Trait Implementations
Auto Trait Implementations
impl<const N: usize, T> !RefUnwindSafe for Chart<N, T>
impl<const N: usize, T> Send for Chart<N, T> where
T: Send,
impl<const N: usize, T> Sync for Chart<N, T> where
T: Send + Sync,
impl<const N: usize, T> Unpin for Chart<N, T> where
T: Unpin,
impl<const N: usize, T> !UnwindSafe for Chart<N, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more