serde_view

Crates.ioserde_view
lib.rsserde_view
version0.1.6
sourcesrc
created_at2023-04-18 08:49:34.451807
updated_at2023-04-27 14:48:58.82425
descriptionSerialize views of data
homepage
repositoryhttps://github.com/ctron/serde-view
max_upload_size
id842314
size28,326
Jim Crossley (jcrossley3)

documentation

README

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())
}
Commit count: 14

cargo fmt