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