Skip to content

Commit

Permalink
Merge pull request #426 from hyperium/auth
Browse files Browse the repository at this point in the history
refactor(auth): adjust Scheme::scheme function to not take a marker Opti...
  • Loading branch information
reem committed Apr 3, 2015
2 parents 8f61dd4 + 0a1916d commit 48bbf4a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st

fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
if raw.len() == 1 {
match (from_utf8(unsafe { &raw.get_unchecked(0)[..] }), Scheme::scheme(None::<S>)) {
match (from_utf8(unsafe { &raw.get_unchecked(0)[..] }), <S as Scheme>::scheme()) {
(Ok(header), Some(scheme))
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
header[scheme.len() + 1..].parse::<S>().map(Authorization).ok()
Expand All @@ -46,7 +46,7 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st

impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match Scheme::scheme(None::<S>) {
match <S as Scheme>::scheme() {
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
None => ()
};
Expand All @@ -58,15 +58,14 @@ impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Er
pub trait Scheme: FromStr + fmt::Debug + Clone + Send + Sync {
/// An optional Scheme name.
///
/// For example, `Basic asdf` has the name `Basic`. The Option<Self> is
/// just a marker that can be removed once UFCS is completed.
fn scheme(Option<Self>) -> Option<&'static str>;
/// Will be replaced with an associated constant once available.
fn scheme() -> Option<&'static str>;
/// Format the Scheme data into a header value.
fn fmt_scheme(&self, &mut fmt::Formatter) -> fmt::Result;
}

impl Scheme for String {
fn scheme(_: Option<String>) -> Option<&'static str> {
fn scheme() -> Option<&'static str> {
None
}

Expand All @@ -86,7 +85,7 @@ pub struct Basic {
}

impl Scheme for Basic {
fn scheme(_: Option<Basic>) -> Option<&'static str> {
fn scheme() -> Option<&'static str> {
Some("Basic")
}

Expand Down

0 comments on commit 48bbf4a

Please sign in to comment.