use crate::Origin;
use core::marker::PhantomData;
use gear_core::{
ids::{ActorId, MessageId},
message::{StoredDispatch, UserStoredMessage},
};
pub trait KeyFor {
type Key;
type Value;
fn key_for(value: &Self::Value) -> Self::Key;
}
pub struct MailboxKeyGen<T>(PhantomData<T>);
impl<T: Origin> KeyFor for MailboxKeyGen<T> {
type Key = (T, MessageId);
type Value = UserStoredMessage;
fn key_for(value: &Self::Value) -> Self::Key {
(value.destination().cast(), value.id())
}
}
pub struct QueueKeyGen;
impl KeyFor for QueueKeyGen {
type Key = MessageId;
type Value = StoredDispatch;
fn key_for(value: &Self::Value) -> Self::Key {
value.id()
}
}
pub struct WaitlistKeyGen;
impl KeyFor for WaitlistKeyGen {
type Key = (ActorId, MessageId);
type Value = StoredDispatch;
fn key_for(value: &Self::Value) -> Self::Key {
(value.destination(), value.id())
}
}