This crate provides a derive macro SemverReq
to build a versioned marker type.
For example, it assocates the type with version "3.1.4".
```rust
struct MyVersion; ``` The marker type works as a version checker during deserialization. In this example, the marker verifies whether the deserialized JSON text is is compatible with version "3.1.4". For example, "3.1.3" and "3.1.0" are valid versions, but "3.2.0" and "2.7.0" are not.
```rust use semver::Version; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use serde_semver::SemverReq;
struct MyVersion;
// An example configuration with version tag
struct Config { pub version: MyVersion, pub inputfile: PathBuf, pub outputfile: PathBuf, }
// The version is audited during deserialization. let config: Config = serdejson::fromstr( r#"{ "version": "3.1.4", "inputfile": "input.txt", "outputfile": "output.txt" }"#, ) .unwrap();
// The version is recovered after serialization. asserteq!( serdejson::tostringpretty(&config).unwrap(), r#"{ "version": "3.1.4", "inputfile": "input.txt", "outputfile": "output.txt" }"#, ); ```
MIT license. See LICENSE.txt file.