@@ -1233,119 +1233,30 @@ impl<'de> de::Deserialize<'de> for TomlDebugInfo {
12331233 }
12341234}
12351235
1236- #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize ) ]
1237- #[ serde( untagged , rename_all = "kebab-case" ) ]
1236+ #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize , Deserialize ) ]
1237+ #[ serde( rename_all = "kebab-case" ) ]
12381238#[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
12391239pub enum TomlTrimPaths {
1240- Values ( Vec < TomlTrimPathsValue > ) ,
1240+ None ,
1241+ Object ,
12411242 All ,
12421243}
12431244
12441245impl TomlTrimPaths {
1245- pub fn none ( ) -> Self {
1246- TomlTrimPaths :: Values ( Vec :: new ( ) )
1247- }
1248-
12491246 pub fn is_none ( & self ) -> bool {
1250- match self {
1251- TomlTrimPaths :: Values ( v) => v. is_empty ( ) ,
1252- TomlTrimPaths :: All => false ,
1253- }
1247+ matches ! ( self , TomlTrimPaths :: None )
12541248 }
1255- }
12561249
1257- impl < ' de > de:: Deserialize < ' de > for TomlTrimPaths {
1258- fn deserialize < D > ( d : D ) -> Result < TomlTrimPaths , D :: Error >
1259- where
1260- D : de:: Deserializer < ' de > ,
1261- {
1262- use serde:: de:: Error as _;
1263- let expecting = r#"a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options"# ;
1264- UntaggedEnumVisitor :: new ( )
1265- . expecting ( expecting)
1266- . bool ( |value| {
1267- Ok ( if value {
1268- TomlTrimPaths :: All
1269- } else {
1270- TomlTrimPaths :: none ( )
1271- } )
1272- } )
1273- . string ( |v| match v {
1274- "none" => Ok ( TomlTrimPaths :: none ( ) ) ,
1275- "all" => Ok ( TomlTrimPaths :: All ) ,
1276- v => {
1277- let d = v. into_deserializer ( ) ;
1278- let err = |_: D :: Error | {
1279- serde_untagged:: de:: Error :: custom ( format ! ( "expected {expecting}" ) )
1280- } ;
1281- TomlTrimPathsValue :: deserialize ( d)
1282- . map_err ( err)
1283- . map ( |v| v. into ( ) )
1284- }
1285- } )
1286- . seq ( |seq| {
1287- let seq: Vec < String > = seq. deserialize ( ) ?;
1288- let seq: Vec < _ > = seq
1289- . into_iter ( )
1290- . map ( |s| TomlTrimPathsValue :: deserialize ( s. into_deserializer ( ) ) )
1291- . collect :: < Result < _ , _ > > ( ) ?;
1292- Ok ( seq. into ( ) )
1293- } )
1294- . deserialize ( d)
1295- }
1296- }
1297-
1298- impl fmt:: Display for TomlTrimPaths {
1299- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1250+ fn as_str ( & self ) -> & ' static str {
13001251 match self {
1301- TomlTrimPaths :: All => write ! ( f, "all" ) ,
1302- TomlTrimPaths :: Values ( v) if v. is_empty ( ) => write ! ( f, "none" ) ,
1303- TomlTrimPaths :: Values ( v) => {
1304- let mut iter = v. iter ( ) ;
1305- if let Some ( value) = iter. next ( ) {
1306- write ! ( f, "{value}" ) ?;
1307- }
1308- for value in iter {
1309- write ! ( f, ",{value}" ) ?;
1310- }
1311- Ok ( ( ) )
1312- }
1252+ TomlTrimPaths :: None => "none" ,
1253+ TomlTrimPaths :: Object => "object" ,
1254+ TomlTrimPaths :: All => "all" ,
13131255 }
13141256 }
13151257}
13161258
1317- impl From < TomlTrimPathsValue > for TomlTrimPaths {
1318- fn from ( value : TomlTrimPathsValue ) -> Self {
1319- TomlTrimPaths :: Values ( vec ! [ value] )
1320- }
1321- }
1322-
1323- impl From < Vec < TomlTrimPathsValue > > for TomlTrimPaths {
1324- fn from ( value : Vec < TomlTrimPathsValue > ) -> Self {
1325- TomlTrimPaths :: Values ( value)
1326- }
1327- }
1328-
1329- #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize , Deserialize ) ]
1330- #[ serde( rename_all = "kebab-case" ) ]
1331- #[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
1332- pub enum TomlTrimPathsValue {
1333- Diagnostics ,
1334- Macro ,
1335- Object ,
1336- }
1337-
1338- impl TomlTrimPathsValue {
1339- pub fn as_str ( & self ) -> & ' static str {
1340- match self {
1341- TomlTrimPathsValue :: Diagnostics => "diagnostics" ,
1342- TomlTrimPathsValue :: Macro => "macro" ,
1343- TomlTrimPathsValue :: Object => "object" ,
1344- }
1345- }
1346- }
1347-
1348- impl fmt:: Display for TomlTrimPathsValue {
1259+ impl fmt:: Display for TomlTrimPaths {
13491260 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
13501261 write ! ( f, "{}" , self . as_str( ) )
13511262 }
0 commit comments