diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 294e486..85864cc 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -170,7 +170,7 @@ fn default_value(ty: String) -> String { .to_string() } -/// return type and unwrap with Option and Vec; or return the value type of HashMap and BTreeMap +/// return type and unwrap with Option, Vec, HashSet, BTreeSet; or return the value type of HashMap and BTreeMap fn parse_type( ty: &Type, default: &mut String, @@ -194,7 +194,7 @@ fn parse_type( r#type = parse_type(ty, default, &mut false, nesting_format); } } - } else if id == "Vec" { + } else if id == "Vec" || id == "HashSet" || id == "BTreeSet" { if nesting_format.is_some() { *nesting_format = Some(NestingFormat::Section(NestingType::Vec)); } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 961e758..69e5bdd 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -348,6 +348,36 @@ c = [ 0, ] # Config.d # d = [ 0, ] +"# + ); + assert!(toml::from_str::(&Config::toml_example()).is_ok()) + } + + #[test] + fn hashset_btreeset() { + use std::collections::{BTreeSet, HashSet}; + + #[derive(TomlExample, Deserialize, Default, PartialEq, Debug)] + #[allow(dead_code)] + struct Config { + /// Config.a is a set of string + a: HashSet, + /// Config.b is a set of number + b: BTreeSet, + /// Config.c is optional + c: Option>, + } + assert_eq!( + Config::toml_example(), + r#"# Config.a is a set of string +a = [ "", ] + +# Config.b is a set of number +b = [ 0, ] + +# Config.c is optional +# c = [ "", ] + "# ); assert!(toml::from_str::(&Config::toml_example()).is_ok())