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 47 48 49 50 51 52 53 54 55 56 57 58 59
| mod oauth { use std::marker::PhantomData;
pub struct EndointSet {} pub struct EndpointNotSet {}
pub trait EndpointState {}
impl EndpointState for EndointSet {} impl EndpointState for EndpointNotSet {}
pub struct Client<HasAuthUrl = EndpointNotSet, HasTokenUrl = EndpointNotSet> where HasAuthUrl: EndpointState, HasTokenUrl: EndpointState, { auth_url: Option<String>, token_url: Option<String>, phantom: std::marker::PhantomData<(HasAuthUrl, HasTokenUrl)>, }
impl<HasAuthUrl: EndpointState, HasTokenUrl: EndpointState> Client<HasAuthUrl, HasTokenUrl> { pub fn new() -> Self { Client { auth_url: None, token_url: None, phantom: PhantomData, } }
pub fn set_auth_url(self, auth_url: &str) -> Client<EndointSet, HasTokenUrl> { Client { auth_url: Some(auth_url.to_string()), token_url: self.token_url, phantom: PhantomData, } }
pub fn set_token_url(self, token_url: &str) -> Client<HasAuthUrl, EndointSet> { Client { auth_url: self.auth_url, token_url: Some(token_url.to_string()), phantom: PhantomData, } } }
impl<HasTokenUrl: EndpointState> Client<EndointSet, HasTokenUrl> { pub fn get_auth_url(&self) -> &str { self.auth_url.as_ref().unwrap() } }
impl<HasAuthUrl: EndpointState> Client<HasAuthUrl, EndointSet> { pub fn get_token_url(&self) -> &str { self.token_url.as_ref().unwrap() } } }
|