1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::borrow::Cow;
pub struct AuthToken<'a>(Cow<'a, str>);
impl<'a> AuthToken<'a> {
pub fn new<T>(raw_token: T) -> AuthToken<'a>
where T: Into<Cow<'a, str>>
{
AuthToken(raw_token.into())
}
pub fn to_header(&self) -> ::hyper::header::Authorization<String> {
::hyper::header::Authorization(self.0.as_ref().to_owned())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn make_auth_token_with_str_slice() {
AuthToken::new("token");
}
#[test]
fn make_auth_token_with_owned_string() {
AuthToken::new(String::from("token"));
}
}