tilo_actions/remote/within.rs
1//! How far a caller's requests reach when they continue an invocation.
2
3use super::Caller;
4
5/// How far a caller's requests reach without the person being asked: the
6/// [`Reach`](tilo_action_policy::Reach) of the invocation they continue, if
7/// any. It bounds what the caller may do, not who the caller is: it is
8/// equal for every caller, so a child someone's invocation made is still
9/// theirs to follow and cancel.
10#[derive(Clone, Copy, Debug)]
11pub(super) struct Within(Option<tilo_action_policy::Reach>);
12impl PartialEq for Within {
13 fn eq(&self, _: &Self) -> bool {
14 true
15 }
16}
17impl Eq for Within {}
18impl std::hash::Hash for Within {
19 fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
20}
21
22impl Within {
23 pub(super) const NONE: Self = Self(None);
24
25 /// The reach `reach` bounds a caller to, as it was kept.
26 pub(super) const fn of(reach: Option<tilo_action_policy::Reach>) -> Self {
27 Self(reach)
28 }
29}
30
31impl Caller {
32 /// The same caller, asking as part of an invocation admitted to reach
33 /// `reach`: what goes further runs only once the person confirmed it.
34 /// It only narrows. Set only by the provider that matched the request to
35 /// the invocation it continues, never from a payload.
36 #[must_use]
37 pub fn within(mut self, reach: tilo_action_policy::Reach) -> Self {
38 self.within = Within(Some(
39 self.within.0.map_or(reach, |held| held.narrowed(reach)),
40 ));
41 self
42 }
43
44 /// How far this caller's requests reach without the person being asked,
45 /// when they continue an invocation ([`Self::within`]).
46 #[must_use]
47 pub const fn ceiling(&self) -> Option<tilo_action_policy::Reach> {
48 self.within.0
49 }
50}