Skip to main content

Network

Trait Network 

Source
pub trait Network {
Show 13 methods // Required methods fn n_players(&self) -> usize; fn my_id(&self) -> usize; fn send( &mut self, to: usize, data: &[u8], ) -> impl Future<Output = Result<SendLen>>; fn broadcast( &mut self, data: &[u8], ) -> impl Future<Output = Result<SendLen>>; fn recv( &mut self, from: usize, ) -> impl Future<Output = Result<(Vec<u8>, RecvLen)>>; fn recv_objects_many<'a, T, I>( &mut self, request: I, ) -> impl Future<Output = Result<(Vec<Vec<T>>, RecvLen)>> where T: for<'de> Deserialize<'de> + 'a, I: IntoIterator<Item = &'a ReceiveRequest<T>>; fn send_objects_many<'a, T, I>( &mut self, request: I, ) -> impl Future<Output = Result<SendLen>> where T: Serialize + 'a, I: IntoIterator<Item = &'a SendRequest<'a, T>>; // Provided methods fn send_object<T>( &mut self, to: usize, obj: &T, ) -> impl Future<Output = Result<SendLen>> where T: Serialize { ... } fn send_objects<T>( &mut self, to: usize, objs: &[T], ) -> impl Future<Output = Result<SendLen>> where T: Serialize { ... } fn broadcast_object<T>( &mut self, obj: &T, ) -> impl Future<Output = Result<SendLen>> where T: Serialize { ... } fn broadcast_objects<T>( &mut self, objs: &[T], ) -> impl Future<Output = Result<SendLen>> where T: Serialize { ... } fn recv_object<T>( &mut self, from: usize, ) -> impl Future<Output = Result<(T, RecvLen)>> where T: for<'de> Deserialize<'de> { ... } fn recv_objects<T>( &mut self, from: usize, count: Option<usize>, ) -> impl Future<Output = Result<(Vec<T>, RecvLen)>> where T: for<'de> Deserialize<'de> { ... }
}
Expand description

Asynchronous communication interface for a distributed, multi-node system.

This trait defines the core operations for cluster topology resolution, raw byte transport, and strongly-typed object serialization via postcard. It relies on integer-based node addressing, enforcing the invariant my_id() < n_players(). Provided methods abstract the underlying I/O routines into typed, asynchronous batch processing operations to minimize network fragmentation.

Required Methods§

Source

fn n_players(&self) -> usize

Retrieves the total number of participants in the network.

Source

fn my_id(&self) -> usize

Retrieves the local node identifier within the network. Invariant: my_id() < n_players().

Source

fn send( &mut self, to: usize, data: &[u8], ) -> impl Future<Output = Result<SendLen>>

Transmits a raw byte slice to the designated to node asynchronously. Returns the number of bytes sent.

Source

fn broadcast(&mut self, data: &[u8]) -> impl Future<Output = Result<SendLen>>

Transmits a raw byte slice to all network participants asynchronously. Returns the number of bytes sent.

Source

fn recv( &mut self, from: usize, ) -> impl Future<Output = Result<(Vec<u8>, RecvLen)>>

Awaits and retrieves raw byte data from the designated from node asynchronously. Returns the data vector and byte count.

Source

fn recv_objects_many<'a, T, I>( &mut self, request: I, ) -> impl Future<Output = Result<(Vec<Vec<T>>, RecvLen)>>
where T: for<'de> Deserialize<'de> + 'a, I: IntoIterator<Item = &'a ReceiveRequest<T>>,

Processes an iterator of ReceiveRequest parameters to await and deserialize multiple batches of objects from specified sources.

Source

fn send_objects_many<'a, T, I>( &mut self, request: I, ) -> impl Future<Output = Result<SendLen>>
where T: Serialize + 'a, I: IntoIterator<Item = &'a SendRequest<'a, T>>,

Processes an iterator of SendRequest parameters to serialize and transmit multiple payloads to specified targets.

Provided Methods§

Source

fn send_object<T>( &mut self, to: usize, obj: &T, ) -> impl Future<Output = Result<SendLen>>
where T: Serialize,

Serializes a single object using postcard and transmits the resulting byte vector to the designated to node.

Source

fn send_objects<T>( &mut self, to: usize, objs: &[T], ) -> impl Future<Output = Result<SendLen>>
where T: Serialize,

Serializes a slice of objects using postcard and transmits the resulting byte vector to the designated to node.

Source

fn broadcast_object<T>( &mut self, obj: &T, ) -> impl Future<Output = Result<SendLen>>
where T: Serialize,

Serializes a single object using postcard and broadcasts the resulting byte vector to all network participants.

Source

fn broadcast_objects<T>( &mut self, objs: &[T], ) -> impl Future<Output = Result<SendLen>>
where T: Serialize,

Serializes a slice of objects using postcard and broadcasts the resulting byte vector to all network participants.

Source

fn recv_object<T>( &mut self, from: usize, ) -> impl Future<Output = Result<(T, RecvLen)>>
where T: for<'de> Deserialize<'de>,

Awaits byte data from the from node, deserializing it via postcard into a single object of type T.

Source

fn recv_objects<T>( &mut self, from: usize, count: Option<usize>, ) -> impl Future<Output = Result<(Vec<T>, RecvLen)>>
where T: for<'de> Deserialize<'de>,

Awaits byte data from the from node, deserializing it via postcard into a vector of type T. Validates the resulting vector length against count if Some is provided.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§