Skip to content
Discussion options

You must be logged in to vote

It is not possible to combine two such transformations on a single value. You will need to write your own types and transformation code. You can copy most of BoolFromInt. The transformation code would be something like this:

fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
where
    E: serde::de::Error,
{
    match s {
        "0" => Ok(false),
        "1" => Ok(true),
        unexp => Err(serde::de::Error::invalid_value(
            Unexpected::Str(unexp),
            &"\"0\" or \"1\"",
        )),
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mmirate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants