5 releases
0.1.6 | Apr 27, 2023 |
---|---|
0.1.5 | Apr 21, 2023 |
0.1.3 | Apr 18, 2023 |
0.1.2 | Apr 18, 2023 |
0.1.0 | Apr 18, 2023 |
#22 in #serde-default
Used in serde_view
6KB
101 lines
Serialize views of data
Dynamically select during serialization which fields will be included.
Example
use serde_view::View;
use serde_view::ViewFields;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, View)]
pub struct MyStruct {
id: String,
#[serde(default)]
name: String,
#[serde(default)]
tags: Vec<String>,
}
fn serialize(my: &MyStruct) -> Result<serde_json::Value, serde_json::Error> {
serde_json::to_value(my.as_view().with_fields([
<MyStruct as View>::Fields::Id,
<MyStruct as View>::Fields::Name,
]).unwrap())
}
Dependencies
~1.2–1.7MB
~32K SLoC