Crates.io | serde_view_macros |
lib.rs | serde_view_macros |
version | 0.1.6 |
source | src |
created_at | 2023-04-18 08:48:38.733762 |
updated_at | 2023-04-27 14:48:26.062976 |
description | Serialize views of data |
homepage | |
repository | https://github.com/ctron/serde-view |
max_upload_size | |
id | 842312 |
size | 5,598 |
Dynamically select during serialization which fields will be included.
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())
}