You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Serde allows different enum representations: Internally tagged, Adjacently tagged and Untagged in addition to the default Externally tagged representation see Enum representations in Serde's doc.
Serde gura properly support seralization of such enum representation, but fails to perform deserialization of such representation.
Example:
Internally tagged
use serde::{Deserialize,Serialize};use serde_gura::Result;#[derive(Serialize,Deserialize,PartialEq,Debug)]#[serde(rename_all = "lowercase",tag = "type")]enumMyEnum{Database(Database)}#[derive(Serialize,Deserialize,PartialEq,Debug)]structDatabase{ip:String,port:Vec<u16>,connection_max:u32,enabled:bool,}fnmain() -> Result<()>{// You have some type.let database = MyEnum::Database(Database{ip:"127.0.0.1".to_string(),port:vec![80,8080],connection_max:1200,enabled:true,});let sss_str = serde_gura::to_string(&database)?;println!("{}",&sss_str);// Deserialize it back to a Rust typelet deserialized_database:MyEnum = serde_gura::from_str(&sss_str)?;println!("{:#?}", deserialized_database);Ok(())}
use serde::{Deserialize,Serialize};use serde_gura::Result;#[derive(Serialize,Deserialize,PartialEq,Debug)]#[serde(rename_all = "lowercase",untagged)]enumMyEnum{Database(Database)}#[derive(Serialize,Deserialize,PartialEq,Debug)]structDatabase{ip:String,port:Vec<u16>,connection_max:u32,enabled:bool,}fnmain() -> Result<()>{// You have some type.let database = MyEnum::Database(Database{ip:"127.0.0.1".to_string(),port:vec![80,8080],connection_max:1200,enabled:true,});let sss_str = serde_gura::to_string(&database)?;println!("{}",&sss_str);// Deserialize it back to a Rust typelet deserialized_database:MyEnum = serde_gura::from_str(&sss_str)?;println!("{:#?}", deserialized_database);Ok(())}
use serde::{Deserialize,Serialize};use serde_gura::Result;#[derive(Serialize,Deserialize,PartialEq,Debug)]#[serde(rename_all = "lowercase",tag = "t", content = "c")]enumMyEnum{Database(Database)}#[derive(Serialize,Deserialize,PartialEq,Debug)]structDatabase{ip:String,port:Vec<u16>,connection_max:u32,enabled:bool,}fnmain() -> Result<()>{// You have some type.let database = MyEnum::Database(Database{ip:"127.0.0.1".to_string(),port:vec![80,8080],connection_max:1200,enabled:true,});let sss_str = serde_gura::to_string(&database)?;println!("{}",&sss_str);// Deserialize it back to a Rust typelet deserialized_database:MyEnum = serde_gura::from_str(&sss_str)?;println!("{:#?}", deserialized_database);Ok(())}
All the 3 enums alternatives reported are now supported in version 0.1.3. This issue also allowed me to find some little mistakes that I took the opportunity to correct 👌
Serde allows different enum representations:
Internally tagged
,Adjacently tagged
andUntagged
in addition to the defaultExternally tagged
representation see Enum representations in Serde's doc.Serde gura properly support seralization of such enum representation, but fails to perform deserialization of such representation.
Example:
Internally tagged
Untagged
output
Adjacently tagged
output
The text was updated successfully, but these errors were encountered: