chiark / gitweb /
authproofs: Add some inline annotations
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 30 May 2021 12:27:14 +0000 (13:27 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 30 May 2021 12:44:07 +0000 (13:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/authproofs.rs

index 07dbf9865045e5203faa3472a2bd5b895602eaf7..1d9b5041f7926b38ffd2ba8a2d289ed95373d181 100644 (file)
@@ -10,13 +10,15 @@ pub struct Global;
 #[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)]
@@ -25,25 +27,29 @@ pub struct AuthorisationError(pub String);
 
 #[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)
   }
@@ -51,6 +57,7 @@ impl<T> Authorisation<T> {
 
 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()
   }
@@ -64,6 +71,7 @@ impl From<anyhow::Error> for AuthorisationError {
 
 pub trait AuthorisationCombine: Sized {
   type Output;
+  #[inline]
   fn combine(self) -> Authorisation<Self::Output> {
     Authorisation(PhantomData)
   }