sel4/
invocation_context.rs
1use core::cell::RefCell;
8
9use crate::IpcBuffer;
10
11pub trait InvocationContext {
13 fn with_context<T>(&mut self, f: impl FnOnce(&mut IpcBuffer) -> T) -> T;
14}
15
16#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
18pub struct NoInvocationContext;
19
20impl NoInvocationContext {
21 pub const fn new() -> Self {
22 Self
23 }
24}
25
26impl InvocationContext for &mut IpcBuffer {
27 fn with_context<T>(&mut self, f: impl FnOnce(&mut IpcBuffer) -> T) -> T {
28 f(self)
29 }
30}
31
32impl<U: InvocationContext> InvocationContext for &mut U {
33 fn with_context<T>(&mut self, f: impl FnOnce(&mut IpcBuffer) -> T) -> T {
34 U::with_context(self, f)
35 }
36}
37
38impl<U: InvocationContext> InvocationContext for &RefCell<U> {
39 fn with_context<T>(&mut self, f: impl FnOnce(&mut IpcBuffer) -> T) -> T {
40 U::with_context(&mut self.borrow_mut(), f)
41 }
42}
43
44cfg_if::cfg_if! {
45 if #[cfg(feature = "state")] {
46 type NoExplicitInvocationContextInternal = crate::ImplicitInvocationContext;
47 } else {
48 type NoExplicitInvocationContextInternal = NoInvocationContext;
49 }
50}
51
52pub type NoExplicitInvocationContext = NoExplicitInvocationContextInternal;