pub trait Sharding{
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§
Required Methods§
Sourcefn locate_shard(&self, key: &Self::Key) -> Option<Self::ShardId>
fn locate_shard(&self, key: &Self::Key) -> Option<Self::ShardId>
Map a key to a shard.
Provided Methods§
Sourcefn network_state<'async_trait>(
core: Core,
) -> Pin<Box<dyn Future<Output = HashMap<String, HashSet<PeerId>>> + Send + 'async_trait>>
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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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.