use serde::de::DeserializeOwned;
use crate::{Error, ItemRef, ItemRefList, Resolve, Script};
mod __seal__ {
pub trait Sealed {}
}
impl __seal__::Sealed for Resolve {}
impl __seal__::Sealed for ItemRef {}
#[cfg(feature = "pool")]
impl __seal__::Sealed for crate::PooledResolve {}
pub trait ResolveExecute: __seal__::Sealed {
fn execute<'c, T: DeserializeOwned + Send>(
&'c self,
script: impl Into<Script<'c>> + Send,
) -> impl Future<Output = Result<T, Error>> + Send;
}
pub trait ResolveStore: __seal__::Sealed {
fn store<'c>(
&'c self,
script: impl Into<Script<'c>> + Send,
) -> impl Future<Output = Result<ItemRef, Error>> + Send;
fn store_option<'c>(
&'c self,
script: impl Into<Script<'c>> + Send,
) -> impl Future<Output = Result<Option<ItemRef>, Error>> + Send;
fn store_list<'c>(
&'c self,
script: impl Into<Script<'c>> + Send,
) -> impl Future<Output = Result<ItemRefList, Error>> + Send;
}
macro_rules! impl_execute {
($( $n:path ),*) => {$(
impl ResolveExecute for $n {
fn execute<'c, T: DeserializeOwned + Send>(
&'c self,
script: impl Into<Script<'c>> + Send,
) -> impl Future<Output = Result<T, Error>> + Send {
self.execute(script)
}
}
)*};
}
macro_rules! impl_store {
($( $n:path ),*) => {$(
impl ResolveStore for $n {
fn store<'c>(
&'c self,
script: impl Into<Script<'c>> + Send
) -> impl Future<Output = Result<ItemRef, Error>> + Send {
self.store(script)
}
fn store_option<'c>(
&'c self,
script: impl Into<Script<'c>> + Send
) -> impl Future<Output = Result<Option<ItemRef>, Error>> + Send {
self.store_option(script)
}
fn store_list<'c>(
&'c self,
script: impl Into<Script<'c>> + Send
) -> impl Future<Output = Result<ItemRefList, Error>> + Send {
self.store_list(script)
}
}
)*};
}
impl_execute!(Resolve, ItemRef);
#[cfg(feature = "pool")]
impl_execute!(crate::PooledResolve);
impl_store!(Resolve, ItemRef);