tlns_google_oauth2_traits/lib.rs
1#![doc = include_str!("../README.md")]
2
3use std::fmt::{Debug, Display};
4
5/// Converting enum scopes to string
6pub trait ToGoogleScope: Debug {
7 /// Converting the enum back to [`str`] literal
8 fn to_google_scope(&self) -> &'static str;
9}
10
11/// Converting scope strings to `T`
12pub trait FromGoogleScope<T>: Debug {
13 /// Converting Google Scope string to enum
14 /// This might return [`Err`] if you input an invalid Google Scope.
15 fn from_google_scope(google_scope: &str) -> Result<T, ()>;
16}
17
18impl Display for dyn ToGoogleScope {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 f.write_str(self.to_google_scope())
21 }
22}