Crate pulumi_gestalt_serde_constant_string

Crate pulumi_gestalt_serde_constant_string 

Source
Expand description

This crate provides a macro to generate a constant string type that can be used with Serde for serialization and deserialization. The generated type will serialize to a specific string value and will only deserialize from that exact string value.

ยงExamples

use pulumi_gestalt_serde_constant_string::generate_string_const;
#[derive(Serialize, Deserialize)]
struct MyStruct {
   tpe: IntegerString,
   value: i32,
}
generate_string_const!(IntegerString, "Integer");

assert!(serde_json::from_value::<MyStruct>(json!({ "tpe": "Integer", "value": 1 })).is_ok());
assert!(serde_json::from_value::<MyStruct>(json!({ "tpe": "Double", "value": 2 })).is_err());