#[derive(Debug,Copy,Clone)]
pub struct Unauthorised<T,A> (T, PhantomData<A>);
impl<T,A> Unauthorised<T,A> {
- pub fn of(t: T) -> Self { Unauthorised(t, PhantomData) }
- pub fn by(self, _auth: Authorisation<A>) -> T { self.0 }
+ #[inline] pub fn of(t: T) -> Self { Unauthorised(t, PhantomData) }
+ #[inline] pub fn by(self, _auth: Authorisation<A>) -> T { self.0 }
+ #[inline]
pub fn by_ref(&self, _auth: Authorisation<A>) -> & T { & self.0 }
+ #[inline]
pub fn by_mut(&mut self, _auth: Authorisation<A>) -> &mut T { &mut self.0 }
}
impl<T,A> From<T> for Unauthorised<T,A> {
- fn from(t: T) -> Self { Self::of(t) }
+ #[inline] fn from(t: T) -> Self { Self::of(t) }
}
#[derive(Error,Debug)]
#[derive(Debug)]
pub struct Authorisation<A> (PhantomData<*const A>);
-impl<A> Clone for Authorisation<A> { fn clone(&self) -> Self { *self } }
+impl<A> Clone for Authorisation<A> { #[inline] fn clone(&self)->Self{ *self }}
impl<A> Copy for Authorisation<A> { }
pub type AuthorisationSuperuser = Authorisation<Global>;
impl<T> Authorisation<T> {
/// Proof obligation: access to this `T` has been authorised.
+ #[inline]
pub const fn authorised(_v: &T) -> Authorisation<T> {
Authorisation(PhantomData)
}
+ #[inline]
pub fn map<U,F>(self, _f: F) -> Authorisation<U> where F: Fn(&T) -> &U {
self.therefore_ok()
}
/// Minor proof obligation: in this case, authorised access to `T`
/// implies authorised access to `U`.
+ #[inline]
pub fn therefore_ok<U>(self) -> Authorisation<U> {
Authorisation(PhantomData)
}
/// Proof obligation: access to `T` has been authorised.
+ #[inline]
pub const fn authorise_any() -> Authorisation<T> {
Authorisation(PhantomData)
}
impl<T:Serialize> From<Authorisation<Global>> for Authorisation<T> {
// ^ we need a bound not met by Global or we conflict with From<T> for T
+ #[inline]
fn from(global: Authorisation<Global>) -> Self {
global.therefore_ok()
}
pub trait AuthorisationCombine: Sized {
type Output;
+ #[inline]
fn combine(self) -> Authorisation<Self::Output> {
Authorisation(PhantomData)
}