swarm_nl::core::sharding

Trait Sharding

Source
pub trait Sharding
where Self::Key: Send + Sync, Self::ShardId: ToString + Send + Sync,
{ type Key: ?Sized; type ShardId; // Required method fn locate_shard(&self, key: &Self::Key) -> Option<Self::ShardId>; // Provided methods fn network_state<'async_trait>( core: Core, ) -> Pin<Box<dyn Future<Output = HashMap<String, HashSet<PeerId>>> + Send + 'async_trait>> { ... } fn join_network<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, shard_id: &'life1 Self::ShardId, ) -> Pin<Box<dyn Future<Output = NetworkResult<()>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn exit_network<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, shard_id: &'life1 Self::ShardId, ) -> Pin<Box<dyn Future<Output = NetworkResult<()>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn shard<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, key: &'life1 Self::Key, data: ByteVector, ) -> Pin<Box<dyn Future<Output = NetworkResult<Option<ByteVector>>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn fetch<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, key: &'life1 Self::Key, data: ByteVector, ) -> Pin<Box<dyn Future<Output = NetworkResult<Option<ByteVector>>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } }
Expand description

Trait that specifies sharding logic and behaviour of shards.

Required Associated Types§

Source

type Key: ?Sized

The type of the shard key e.g hash, range etc.

Source

type ShardId

The identifier pointing to a specific shard.

Required Methods§

Source

fn locate_shard(&self, key: &Self::Key) -> Option<Self::ShardId>

Map a key to a shard.

Provided Methods§

Source

fn network_state<'async_trait>( core: Core, ) -> Pin<Box<dyn Future<Output = HashMap<String, HashSet<PeerId>>> + Send + 'async_trait>>

Return the state of the shard network.

Source

fn join_network<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, shard_id: &'life1 Self::ShardId, ) -> Pin<Box<dyn Future<Output = NetworkResult<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Join a shard network.

Source

fn exit_network<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, shard_id: &'life1 Self::ShardId, ) -> Pin<Box<dyn Future<Output = NetworkResult<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Exit a shard network.

Source

fn shard<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, key: &'life1 Self::Key, data: ByteVector, ) -> Pin<Box<dyn Future<Output = NetworkResult<Option<ByteVector>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send data to peers in the appropriate logical shard. It returns the data if the node is a member of the shard after replicating it to fellow nodes in the same shard.

Source

fn fetch<'life0, 'life1, 'async_trait>( &'life0 self, core: Core, key: &'life1 Self::Key, data: ByteVector, ) -> Pin<Box<dyn Future<Output = NetworkResult<Option<ByteVector>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch data from the shard network. It returns None if the node is a memnber of the shard with the data, meaning the node should read it locally.

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§