use super::{
DeRecChannelStore, DeRecSecretStore, DeRecShareStore, DeRecStateStore, DeRecTransport,
DeRecUserSecretStore,
};
use std::marker::PhantomData;
pub(crate) trait StoreSet {
type Channels: DeRecChannelStore;
type Shares: DeRecShareStore;
type Secrets: DeRecSecretStore;
type UserSecrets: DeRecUserSecretStore;
type State: DeRecStateStore;
type Transport: DeRecTransport;
}
pub(crate) struct Set<Ch, Sh, Ss, Us, St, T>(PhantomData<(Ch, Sh, Ss, Us, St, T)>);
impl<Ch, Sh, Ss, Us, St, T> StoreSet for Set<Ch, Sh, Ss, Us, St, T>
where
Ch: DeRecChannelStore,
Sh: DeRecShareStore,
Ss: DeRecSecretStore,
Us: DeRecUserSecretStore,
St: DeRecStateStore,
T: DeRecTransport,
{
type Channels = Ch;
type Shares = Sh;
type Secrets = Ss;
type UserSecrets = Us;
type State = St;
type Transport = T;
}
pub(crate) struct Stores<'a, S: StoreSet> {
pub(crate) channels: &'a mut S::Channels,
pub(crate) shares: &'a mut S::Shares,
pub(crate) secrets: &'a mut S::Secrets,
pub(crate) user_secrets: &'a mut S::UserSecrets,
pub(crate) state: &'a mut S::State,
pub(crate) transport: &'a S::Transport,
}
impl<'a, Ch, Sh, Ss, Us, St, T> Stores<'a, Set<Ch, Sh, Ss, Us, St, T>>
where
Ch: DeRecChannelStore,
Sh: DeRecShareStore,
Ss: DeRecSecretStore,
Us: DeRecUserSecretStore,
St: DeRecStateStore,
T: DeRecTransport,
{
pub(crate) fn new(
channels: &'a mut Ch,
shares: &'a mut Sh,
secrets: &'a mut Ss,
user_secrets: &'a mut Us,
state: &'a mut St,
transport: &'a T,
) -> Self {
Self {
channels,
shares,
secrets,
user_secrets,
state,
transport,
}
}
}
macro_rules! borrow_stores {
($protocol:expr) => {
$crate::protocol::stores::Stores::new(
&mut $protocol.channel_store,
&mut $protocol.share_store,
&mut $protocol.secret_store,
&mut $protocol.user_secret_store,
&mut $protocol.state_store,
&$protocol.transport,
)
};
}
pub(crate) use borrow_stores;