-
-
Notifications
You must be signed in to change notification settings - Fork 80
Description
Hello.
Thanks for making this crate. I generally use it as a convenience for simple things but had to look a little deep to determine if the #[serde_as]
macro accepted deserialization and serialization specific conversion.
On the docs the field level attributes are mentioned very briefly, possibly too far down for most people to read. It may be helpful to newer users if they just see it in the example at the top of the page. Obviously, people should read the docs... but that is not always the case.
I was thinking something like below. Just a visual signpost to say "You can do this".
People familiar with serde and the attributes could intuit them working. For new users to serde and Rust in general, maybe not.
Maybe there is a good place to throw no_default
on there as well. Is this considered worthwhile for an addition through a PR?
#[serde_as]
#[derive(Serialize, Deserialize)]
struct Data {
/// Serialize into number
#[serde_as(as = "_")]
a: u32,
/// Serialize into String,
/// Deserialize from Bytes or String,
#[serde_as(
serialize_as = "DisplayFromStr",
deserialize_as = "BytesOrString"
)]
b: u32,
/// Serialize into a map from String to String
#[serde_as(as = "Map<DisplayFromStr, _>")]
c: Vec<(u32, String)>,
}