pub struct FrictionGate<D: Gateable> { /* private fields */ }Expand description
Compile-time-checked friction wrapper. Construct via
FrictionGate::new, which accepts only Increases-typed
commands; the function signature prevents callers from
accidentally friction-wrapping a risk-reducing action.
§Risk-asymmetry invariant (compile-time)
The point of the type parameter is to make this line unable to compile:
ⓘ
use zero_commands::risk::FrictionGate;
// A local `Reduces` phantom. Not `Gateable` — there is no
// way for an external crate to make it `Gateable`, because
// `Gateable` is sealed to this crate (see `sealed` module).
#[derive(Clone, Copy)]
struct Reduces;
// This must be a compile error, not a runtime one. If it
// compiles, the type-level guarantee is gone and a
// risk-reducing command could be wrapped in friction.
let _: FrictionGate<Reduces> = FrictionGate::new();The control is also positive: a FrictionGate<Increases>
is constructible and reports its direction honestly.
use zero_commands::risk::{FrictionGate, Increases, RiskDirection};
let g = FrictionGate::<Increases>::new();
assert_eq!(g.direction(), RiskDirection::Increases);Implementations§
Source§impl FrictionGate<Increases>
impl FrictionGate<Increases>
pub const fn new() -> Self
Sourcepub const fn direction(&self) -> RiskDirection
pub const fn direction(&self) -> RiskDirection
The direction this gate operates on. Useful for logging when a friction pause is shown to the operator.
Trait Implementations§
Source§impl<D: Clone + Gateable> Clone for FrictionGate<D>
impl<D: Clone + Gateable> Clone for FrictionGate<D>
Source§fn clone(&self) -> FrictionGate<D>
fn clone(&self) -> FrictionGate<D>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for FrictionGate<Increases>
impl Default for FrictionGate<Increases>
impl<D: Copy + Gateable> Copy for FrictionGate<D>
Auto Trait Implementations§
impl<D> Freeze for FrictionGate<D>
impl<D> RefUnwindSafe for FrictionGate<D>where
D: RefUnwindSafe,
impl<D> Send for FrictionGate<D>where
D: Send,
impl<D> Sync for FrictionGate<D>where
D: Sync,
impl<D> Unpin for FrictionGate<D>where
D: Unpin,
impl<D> UnsafeUnpin for FrictionGate<D>
impl<D> UnwindSafe for FrictionGate<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more