-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: add
OneOrMore
enum for deserializing either singletons or strings
- Loading branch information
Showing
4 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum OneOrMore<T> { | ||
One(T), | ||
List(Vec<T>), | ||
} | ||
|
||
impl<T> From<T> for OneOrMore<T> { | ||
fn from(one: T) -> Self { | ||
OneOrMore::One(one) | ||
} | ||
} | ||
|
||
impl<T> From<Vec<T>> for OneOrMore<T> { | ||
fn from(vec: Vec<T>) -> Self { | ||
OneOrMore::List(vec) | ||
} | ||
} | ||
|
||
impl From<&str> for OneOrMore<String> { | ||
fn from(s: &str) -> Self { | ||
OneOrMore::One(s.to_owned()) | ||
} | ||
} |
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