From 28fbf35779c4025edbb13fd06f98bac13d3405e9 Mon Sep 17 00:00:00 2001 From: Baptiste Gelez Date: Wed, 24 Oct 2018 12:21:42 +0100 Subject: [PATCH] Use PhantomData intead of two Options useless for Authorization And remove some warnings about unused parameters --- plume-models/src/apps.rs | 8 ++++---- src/api/authorization.rs | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/plume-models/src/apps.rs b/plume-models/src/apps.rs index a3446c65..5aebc6bf 100755 --- a/plume-models/src/apps.rs +++ b/plume-models/src/apps.rs @@ -31,11 +31,11 @@ pub struct NewApp { impl Provider for App { type Data = AppEndpoint; - fn get(conn: &Connection, id: i32) -> Result { + fn get(_conn: &Connection, _id: i32) -> Result { unimplemented!() } - fn list(conn: &Connection, query: AppEndpoint) -> Vec { + fn list(_conn: &Connection, _query: AppEndpoint) -> Vec { unimplemented!() } @@ -61,11 +61,11 @@ impl Provider for App { }) } - fn update(conn: &Connection, id: i32, new_data: AppEndpoint) -> Result { + fn update(_conn: &Connection, _id: i32, _new_data: AppEndpoint) -> Result { unimplemented!() } - fn delete(conn: &Connection, id: i32) { + fn delete(_conn: &Connection, _id: i32) { unimplemented!() } } diff --git a/src/api/authorization.rs b/src/api/authorization.rs index faebac57..20650887 100644 --- a/src/api/authorization.rs +++ b/src/api/authorization.rs @@ -3,6 +3,7 @@ use rocket::{ http::Status, request::{self, FromRequest, Request} }; +use std::marker::PhantomData; use plume_models::{self, api_tokens::ApiToken}; // Actions @@ -32,11 +33,7 @@ impl Scope for plume_models::posts::Post { } } -// We have to use A and S in the struct definition -// otherwise rustc complains they are useless -// -// A nicer solution is probably possible. -pub struct Authorization (Option, Option); +pub struct Authorization (PhantomData<(A, S)>); impl<'a, 'r, A, S> FromRequest<'a, 'r> for Authorization where A: Action, @@ -48,7 +45,7 @@ where A: Action, request.guard::() .map_failure(|_| (Status::Unauthorized, ())) .and_then(|token| if token.can(A::to_str(), S::to_str()) { - Outcome::Success(Authorization(None, None)) + Outcome::Success(Authorization(PhantomData)) } else { Outcome::Failure((Status::Unauthorized, ())) })