chiark / gitweb /
before split up OnlineError for trait coherence
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 30 Dec 2020 11:39:43 +0000 (11:39 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 30 Dec 2020 11:39:43 +0000 (11:39 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/main.rs
src/global.rs

index fbaec774b84259372112836390a4b9d46f25c9cf..37dab2f50232b16f721d50ea87124000adad19ee 100644 (file)
@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // There is NO WARRANTY.
 
-use super::*;
+pub use super::*;
 
 type WRC = WhatResponseToClientOp;
 
@@ -10,12 +10,14 @@ type PL = PresentationLayout;
 
 pub struct AbbrevPresentationLayout(pub PresentationLayout);
 
-impl<'r> FromParam<'r> for AbbrevPresentationLayout {
+/*
+impl<'r> FromParam<'r> for PresentationLayout {
   type Error = strum::ParseError;
   fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
-    AbbrevPresentationLayout(param.as_str().parse())
+    param.as_str().parse()
   }
 }
+*/
 
 impl<'r> FromParam<'r> for AbbrevPresentationLayout {
   type Error = ();
@@ -41,10 +43,9 @@ impl<'r, Id> FromFormValue<'r> for InstanceAccess<'r, Id>
   type Error = OE;
   #[throws(OE)]
   fn from_form_value(param: &'r RawStr) -> Self {
-    let g = Id::global_tokens(PRIVATE_Y).read().unwrap();
     let token = RawTokenVal::from_str(param.as_str());
-    let i = g.get(token).ok_or(Id::ERROR)?;
-    InstanceAccess { raw_token : token, i : i.clone() }
+    let i = InstanceAccessDetails::from_token(&token);
+    InstanceAccess { raw_token : token, i }
   }
 }
 
index 23730617624c0818cad965bda24dd2fb6b6807b2..f37236a472b145b577210703b1fae051ef2e883a 100644 (file)
@@ -23,8 +23,7 @@ pub use rocket_contrib::templates::tera::{self, Value};
 pub use rocket_contrib::templates::Engines;
 pub use rocket_contrib::templates::Template;
 
-pub use crate::api::{AbbrevPresentationLayout};
-pub use crate::api::{ApiPieceOpError, Lens, TransparentLens};
+pub use crate::api::{AbbrevPresentationLayout, InstanceAccess};
 pub use crate::cmdlistener::*;
 
 use rocket::fairing;
index df1d1324506014253744228f5feb5d13d45e9ac7..46aecdba780d3ba1eed7bc4b4e4d1aa503f1bf13 100644 (file)
@@ -450,6 +450,17 @@ impl Display for InstanceName {
 
 // ---------- Player and token functionality ----------
 
+impl<Id> InstanceAccessDetails<Id>
+  where Id: AccessId, OE: From<Id::Error>
+{
+  #[throws(OE)]
+  pub fn from_token(token: &RawToken) -> InstanceAccessDetails<Id> {
+    let g = Id::global_tokens(PRIVATE_Y).read().unwrap();
+    let i = g.get(token).ok_or(Id::ERROR)?;
+    i.clone()
+  }
+}
+
 impl<'ig> InstanceGuard<'ig> {
   /// caller is responsible for logging; threading it through
   /// proves the caller has a log entry.