serde-request-envelope 0.1.2

A serde request envelope with named type and data fields.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 1 items with examples
  • Size
  • Source code size: 16.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.74 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • esmevane

Serde Request Envelope

This crate provides the Request struct, which is a newtype wrapper that takes any given serde friendly type and turns it into a request envelope that includes the type name of the given type. This lets you do tagged structures without having to manually curate enums.

For example:

use serde::{Deserialize, Serialize};
use serde_request_envelope::Request;

#[derive(Serialize, Deserialize, Debug)]
struct MyStruct {
   field: String,
}

# fn main() {
let my_struct = MyStruct {
   field: "Hello, World!".to_string(),
};

let request = Request::new(my_struct);

let serialized = serde_json::to_string(&request).unwrap();
// serialized is now: {"type":"MyStruct","data":{"field":"Hello, World!"}}

let deserialized: Request<MyStruct> = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized.0.field, "Hello, World!");
# }