refactor(auth): adjust Scheme::scheme function to not take a marker Option
This commit is contained in:
@@ -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>> {
|
fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
|
||||||
if raw.len() == 1 {
|
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))
|
(Ok(header), Some(scheme))
|
||||||
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
|
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
|
||||||
header[scheme.len() + 1..].parse::<S>().map(Authorization).ok()
|
header[scheme.len() + 1..].parse::<S>().map(Authorization).ok()
|
||||||
@@ -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 {
|
impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
|
||||||
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
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)),
|
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
|
||||||
None => ()
|
None => ()
|
||||||
};
|
};
|
||||||
@@ -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 {
|
pub trait Scheme: FromStr + fmt::Debug + Clone + Send + Sync {
|
||||||
/// An optional Scheme name.
|
/// An optional Scheme name.
|
||||||
///
|
///
|
||||||
/// For example, `Basic asdf` has the name `Basic`. The Option<Self> is
|
/// Will be replaced with an associated constant once available.
|
||||||
/// just a marker that can be removed once UFCS is completed.
|
fn scheme() -> Option<&'static str>;
|
||||||
fn scheme(Option<Self>) -> Option<&'static str>;
|
|
||||||
/// Format the Scheme data into a header value.
|
/// Format the Scheme data into a header value.
|
||||||
fn fmt_scheme(&self, &mut fmt::Formatter) -> fmt::Result;
|
fn fmt_scheme(&self, &mut fmt::Formatter) -> fmt::Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scheme for String {
|
impl Scheme for String {
|
||||||
fn scheme(_: Option<String>) -> Option<&'static str> {
|
fn scheme() -> Option<&'static str> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +85,7 @@ pub struct Basic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Scheme for Basic {
|
impl Scheme for Basic {
|
||||||
fn scheme(_: Option<Basic>) -> Option<&'static str> {
|
fn scheme() -> Option<&'static str> {
|
||||||
Some("Basic")
|
Some("Basic")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user