From: Ian Jackson Date: Wed, 30 Dec 2020 11:39:43 +0000 (+0000) Subject: before split up OnlineError for trait coherence X-Git-Tag: otter-0.2.0~76 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2319074da21e3acb96b9c54c9342fbc4f30fc89b;p=otter.git before split up OnlineError for trait coherence Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index fbaec774..37dab2f5 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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 { - 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 } } } diff --git a/daemon/main.rs b/daemon/main.rs index 23730617..f37236a4 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -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; diff --git a/src/global.rs b/src/global.rs index df1d1324..46aecdba 100644 --- a/src/global.rs +++ b/src/global.rs @@ -450,6 +450,17 @@ impl Display for InstanceName { // ---------- Player and token functionality ---------- +impl InstanceAccessDetails + where Id: AccessId, OE: From +{ + #[throws(OE)] + pub fn from_token(token: &RawToken) -> InstanceAccessDetails { + 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.