This field can be `true/false` or `"true"/"false"`

master
Paul Woolcock 6 years ago
parent e5175f09fe
commit 2e8ee7e840
  1. 26
      src/entities/account.rs

@ -4,6 +4,7 @@ use chrono::prelude::*;
use reqwest::multipart::Form; use reqwest::multipart::Form;
use ::Result; use ::Result;
use std::path::Path; use std::path::Path;
use serde::de::{self, Deserialize, Deserializer, Unexpected};
/// A struct representing an Account. /// A struct representing an Account.
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
@ -51,10 +52,35 @@ pub struct Account {
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct Source { pub struct Source {
privacy: ::status_builder::Visibility, privacy: ::status_builder::Visibility,
#[serde(deserialize_with = "string_or_bool")]
sensitive: bool, sensitive: bool,
note: String, note: String,
} }
fn string_or_bool<'de, D: Deserializer<'de>>(val: D)
-> ::std::result::Result<bool, D::Error>
{
#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub enum BoolOrString {
Bool(bool),
Str(String),
}
Ok(match BoolOrString::deserialize(val)? {
BoolOrString::Bool(b) => b,
BoolOrString::Str(ref s) => {
if s == "true" {
true
} else if s == "false" {
false
} else {
return Err(de::Error::invalid_value(Unexpected::Str(s), &"true or false"));
}
}
})
}
pub struct CredientialsBuilder<'a> { pub struct CredientialsBuilder<'a> {
display_name: Option<&'a str>, display_name: Option<&'a str>,
note: Option<&'a str>, note: Option<&'a str>,

Loading…
Cancel
Save