Skip to main content

atomr_cluster_sharding/
entity_ref.rs

1//! A typed handle to an entity inside a shard region.
2
3use std::marker::PhantomData;
4use std::sync::Arc;
5
6use crate::shard_region::ShardRegion;
7
8#[derive(Clone)]
9pub struct EntityRef<E: crate::extractor::MessageExtractor> {
10    pub(crate) region: Arc<ShardRegion<E>>,
11    pub(crate) entity_id: String,
12    _marker: PhantomData<E>,
13}
14
15impl<E: crate::extractor::MessageExtractor> EntityRef<E> {
16    pub fn new(region: Arc<ShardRegion<E>>, entity_id: String) -> Self {
17        Self { region, entity_id, _marker: PhantomData }
18    }
19
20    pub fn entity_id(&self) -> &str {
21        &self.entity_id
22    }
23
24    pub fn tell(&self, msg: E::Message) {
25        self.region.deliver(msg);
26    }
27}