Last active
August 7, 2017 18:15
-
-
Save sethlopezme/be69b56d2948d97bdd5b62807318f5d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] | |
pub enum Scope { | |
Any, | |
Account, | |
Edit, | |
// ... | |
} | |
impl fmt::Display for Scope { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
match *self { | |
Scope::Any => write!(f, "*"), | |
Scope::Account => write!(f, "account"), | |
Scope::Edit => write!(f, "edit"), | |
// ... | |
} | |
} | |
} | |
#[derive(Debug, Default)] | |
pub struct Scopes(HashSet<Scope>); | |
impl Serialize for Scopes { | |
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | |
where | |
S: Serializer, | |
{ | |
let scope_string = self.0.iter().fold(String::new(), |mut accumulator, scope| { | |
if !accumulator.is_empty() { | |
accumulator.push(' '); | |
} | |
accumulator + scope.to_string().as_str() | |
}); | |
serializer.serialize_str(scope_string.as_str()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment