pi_async_runtime_core/context/
access.rs1use super::record;
2use crate::{
3 block_on::RuntimeBlockOn, control::RuntimeControl, definitions::CurrentRuntimeAccessError,
4 dispatch::*, time::RuntimeTime, wait::RuntimeWait,
5};
6
7pub trait RuntimeContext: TaskDispatch + RuntimeTime {
9 type Handle: Runtime<Notifier = Self::Notifier, Timer = Self::Timer, Handle = Self::Handle>
10 + Clone
11 + Send
12 + Sync
13 + 'static;
14 fn handle(&self) -> Self::Handle;
16 fn try_current() -> pi_result::RawResult<Self::Handle, CurrentRuntimeAccessError> {
20 record::try_current::<Self::Handle>()
21 }
22 fn try_with_current<R>(
24 action: impl FnOnce(&Self::Handle) -> R,
25 ) -> pi_result::RawResult<R, CurrentRuntimeAccessError> {
26 record::try_with_current::<Self::Handle, R>(action)
27 }
28 fn enter<R>(
30 &self,
31 action: impl FnOnce() -> R,
32 ) -> pi_result::RawResult<R, CurrentRuntimeAccessError> {
33 record::with_selected(self.handle(), action)
34 }
35}
36
37pub trait Runtime:
39 TaskDispatch
40 + LocalTaskDispatch
41 + IdleDispatch
42 + TimedTaskDispatch
43 + RuntimeWait
44 + RuntimeControl
45 + RuntimeContext
46 + RuntimeBlockOn
47{
48}
49impl<T> Runtime for T where
50 T: TaskDispatch
51 + LocalTaskDispatch
52 + IdleDispatch
53 + TimedTaskDispatch
54 + RuntimeWait
55 + RuntimeControl
56 + RuntimeContext
57 + RuntimeBlockOn
58{
59}