Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Jonas Platte
Jonas Platte
@jplatte@social.tchncs.de  ·  activity timestamp 8 hours ago

Unfair #rustlang #serde Quiz: What's the difference between these four types' deserialization behavior (ignoring the type name)?

#[derive(Deserialize)]
struct One {
field: Option<String>,
}

#[derive(Deserialize)]
struct Two {
#[serde(default)]
field: Option<String>,
}

#[derive(Deserialize)]
struct Three {
#[serde(deserialize_with = "Option::deserialize")]
field: Option<String>,
}

#[derive(Deserialize)]
struct Four {
#[serde(default, deserialize_with = "Option::deserialize")]
field: Option<String>,
}

  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.2-alpha.29 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct