Crates.io | serde_view |
lib.rs | serde_view |
version | 0.1.6 |
source | src |
created_at | 2023-04-18 08:49:34.451807 |
updated_at | 2023-04-27 14:48:58.82425 |
description | Serialize views of data |
homepage | |
repository | https://github.com/ctron/serde-view |
max_upload_size | |
id | 842314 |
size | 28,326 |
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())
}