Skip to content

Commit 48bbf4a

Browse files
committed
Merge pull request #426 from hyperium/auth
refactor(auth): adjust Scheme::scheme function to not take a marker Opti...
2 parents 8f61dd4 + 0a1916d commit 48bbf4a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/header/common/authorization.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st
3030

3131
fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
3232
if raw.len() == 1 {
33-
match (from_utf8(unsafe { &raw.get_unchecked(0)[..] }), Scheme::scheme(None::<S>)) {
33+
match (from_utf8(unsafe { &raw.get_unchecked(0)[..] }), <S as Scheme>::scheme()) {
3434
(Ok(header), Some(scheme))
3535
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
3636
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
4646

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

6867
impl Scheme for String {
69-
fn scheme(_: Option<String>) -> Option<&'static str> {
68+
fn scheme() -> Option<&'static str> {
7069
None
7170
}
7271

@@ -86,7 +85,7 @@ pub struct Basic {
8685
}
8786

8887
impl Scheme for Basic {
89-
fn scheme(_: Option<Basic>) -> Option<&'static str> {
88+
fn scheme() -> Option<&'static str> {
9089
Some("Basic")
9190
}
9291

0 commit comments

Comments
 (0)