From eae9f5ca1357dc932f85a4bb03e625fd783b07a2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 30 May 2021 13:27:14 +0100 Subject: [PATCH] authproofs: Add some inline annotations Signed-off-by: Ian Jackson --- src/authproofs.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/authproofs.rs b/src/authproofs.rs index 07dbf986..1d9b5041 100644 --- a/src/authproofs.rs +++ b/src/authproofs.rs @@ -10,13 +10,15 @@ pub struct Global; #[derive(Debug,Copy,Clone)] pub struct Unauthorised (T, PhantomData); impl Unauthorised { - pub fn of(t: T) -> Self { Unauthorised(t, PhantomData) } - pub fn by(self, _auth: Authorisation) -> T { self.0 } + #[inline] pub fn of(t: T) -> Self { Unauthorised(t, PhantomData) } + #[inline] pub fn by(self, _auth: Authorisation) -> T { self.0 } + #[inline] pub fn by_ref(&self, _auth: Authorisation) -> & T { & self.0 } + #[inline] pub fn by_mut(&mut self, _auth: Authorisation) -> &mut T { &mut self.0 } } impl From for Unauthorised { - fn from(t: T) -> Self { Self::of(t) } + #[inline] fn from(t: T) -> Self { Self::of(t) } } #[derive(Error,Debug)] @@ -25,25 +27,29 @@ pub struct AuthorisationError(pub String); #[derive(Debug)] pub struct Authorisation (PhantomData<*const A>); -impl Clone for Authorisation { fn clone(&self) -> Self { *self } } +impl Clone for Authorisation { #[inline] fn clone(&self)->Self{ *self }} impl Copy for Authorisation { } pub type AuthorisationSuperuser = Authorisation; impl Authorisation { /// Proof obligation: access to this `T` has been authorised. + #[inline] pub const fn authorised(_v: &T) -> Authorisation { Authorisation(PhantomData) } + #[inline] pub fn map(self, _f: F) -> Authorisation 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(self) -> Authorisation { Authorisation(PhantomData) } /// Proof obligation: access to `T` has been authorised. + #[inline] pub const fn authorise_any() -> Authorisation { Authorisation(PhantomData) } @@ -51,6 +57,7 @@ impl Authorisation { impl From> for Authorisation { // ^ we need a bound not met by Global or we conflict with From for T + #[inline] fn from(global: Authorisation) -> Self { global.therefore_ok() } @@ -64,6 +71,7 @@ impl From for AuthorisationError { pub trait AuthorisationCombine: Sized { type Output; + #[inline] fn combine(self) -> Authorisation { Authorisation(PhantomData) } -- 2.30.2