Skip to content

Commit

Permalink
Use PhantomData intead of two Options useless for Authorization
Browse files Browse the repository at this point in the history
And remove some warnings about unused parameters
  • Loading branch information
elegaanz committed Oct 24, 2018
1 parent 8e4ab95 commit beb3d86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions plume-models/src/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub struct NewApp {
impl Provider<Connection> for App {
type Data = AppEndpoint;

fn get(conn: &Connection, id: i32) -> Result<AppEndpoint, Error> {
fn get(_conn: &Connection, _id: i32) -> Result<AppEndpoint, Error> {
unimplemented!()
}

fn list(conn: &Connection, query: AppEndpoint) -> Vec<AppEndpoint> {
fn list(_conn: &Connection, _query: AppEndpoint) -> Vec<AppEndpoint> {
unimplemented!()
}

Expand All @@ -61,11 +61,11 @@ impl Provider<Connection> for App {
})
}

fn update(conn: &Connection, id: i32, new_data: AppEndpoint) -> Result<AppEndpoint, Error> {
fn update(_conn: &Connection, _id: i32, _new_data: AppEndpoint) -> Result<AppEndpoint, Error> {
unimplemented!()
}

fn delete(conn: &Connection, id: i32) {
fn delete(_conn: &Connection, _id: i32) {
unimplemented!()
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/api/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rocket::{
http::Status,
request::{self, FromRequest, Request}
};
use std::marker::PhantomData;
use plume_models::{self, api_tokens::ApiToken};

// Actions
Expand Down Expand Up @@ -36,7 +37,7 @@ impl Scope for plume_models::posts::Post {
// otherwise rustc complains they are useless
//
// A nicer solution is probably possible.
pub struct Authorization<A, S> (Option<A>, Option<S>);
pub struct Authorization<A, S> (PhantomData<(A, S)>);

impl<'a, 'r, A, S> FromRequest<'a, 'r> for Authorization<A, S>
where A: Action,
Expand All @@ -48,7 +49,7 @@ where A: Action,
request.guard::<ApiToken>()
.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, ()))
})
Expand Down

0 comments on commit beb3d86

Please sign in to comment.