-
-
Save durka/d6a247f8c8f66ed71639a1c36c56c656 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| macro_rules! deser { | |
| ($name:ident, $expect:expr, |$s:ident| $pred:expr) => { | |
| fn $name<'de, D: ::serde::Deserializer<'de>>(de: D) -> StdResult<bool, D::Error> { | |
| struct Visitor; | |
| impl<'de> ::serde::de::Visitor<'de> for Visitor { | |
| type Value = bool; | |
| fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | |
| fmt.write_str($expect) | |
| } | |
| fn visit_str<E: ::serde::de::Error>(self, $s: &str) -> StdResult<bool, E> { | |
| Ok($pred) | |
| } | |
| } | |
| de.deserialize_str(Visitor) | |
| } | |
| } | |
| } | |
| deser!(check_to_bool, "an empty string or a check mark ✓", |s| !s.is_empty()); | |
| deser!(yesno_to_bool, "Yes or No", |s| s == "Yes"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment