use super::record;
use crate::{
block_on::RuntimeBlockOn, control::RuntimeControl, definitions::CurrentRuntimeAccessError,
dispatch::*, time::RuntimeTime, wait::RuntimeWait,
};
pub trait RuntimeContext: TaskDispatch + RuntimeTime {
type Handle: Runtime<Notifier = Self::Notifier, Timer = Self::Timer, Handle = Self::Handle>
+ Clone
+ Send
+ Sync
+ 'static;
fn handle(&self) -> Self::Handle;
fn try_current() -> pi_result::RawResult<Self::Handle, CurrentRuntimeAccessError> {
record::try_current::<Self::Handle>()
}
fn try_with_current<R>(
action: impl FnOnce(&Self::Handle) -> R,
) -> pi_result::RawResult<R, CurrentRuntimeAccessError> {
record::try_with_current::<Self::Handle, R>(action)
}
fn enter<R>(
&self,
action: impl FnOnce() -> R,
) -> pi_result::RawResult<R, CurrentRuntimeAccessError> {
record::with_selected(self.handle(), action)
}
}
pub trait Runtime:
TaskDispatch
+ LocalTaskDispatch
+ IdleDispatch
+ TimedTaskDispatch
+ RuntimeWait
+ RuntimeControl
+ RuntimeContext
+ RuntimeBlockOn
{
}
impl<T> Runtime for T where
T: TaskDispatch
+ LocalTaskDispatch
+ IdleDispatch
+ TimedTaskDispatch
+ RuntimeWait
+ RuntimeControl
+ RuntimeContext
+ RuntimeBlockOn
{
}