diff --git a/filecaster-derive/src/from_file.rs b/filecaster-derive/src/from_file.rs index 4ba1726..e1509e5 100644 --- a/filecaster-derive/src/from_file.rs +++ b/filecaster-derive/src/from_file.rs @@ -174,13 +174,13 @@ fn parse_default(list: &MetaList) -> Result> { let value = meta.value()?; let expr = value.parse::()?; - if let Expr::Lit(expr_lit) = &expr { - if let Lit::Str(lit_str) = &expr_lit.lit { - default_expr = Some(parse_quote! { - #lit_str.to_string() - }); - return Ok(()); - } + if let Expr::Lit(expr_lit) = &expr + && let Lit::Str(lit_str) = &expr_lit.lit + { + default_expr = Some(parse_quote! { + #lit_str.to_string() + }); + return Ok(()); } default_expr = Some(expr); } diff --git a/filecaster/examples/simple.rs b/filecaster/examples/simple.rs index 17f3df1..008d833 100644 --- a/filecaster/examples/simple.rs +++ b/filecaster/examples/simple.rs @@ -40,9 +40,9 @@ fn main() { // Example assertions (adjust based on your actual file contents) assert_eq!(json_data.key, "json key".to_string()); assert_eq!(json_data.number, 123); - assert_eq!(json_data.exists, false); // `bool::default()` is `false` + assert!(!json_data.exists); // `bool::default()` is `false` assert_eq!(toml_data.key, "default key".to_string()); assert_eq!(toml_data.number, 456); - assert_eq!(toml_data.exists, true); + assert!(toml_data.exists); } diff --git a/filecaster/tests/ui/enum_not_supported.stderr b/filecaster/tests/ui/enum_not_supported.stderr new file mode 100644 index 0000000..2247272 --- /dev/null +++ b/filecaster/tests/ui/enum_not_supported.stderr @@ -0,0 +1,6 @@ +error: FromFile only works on structs. + Enums are not supported. + --> tests/ui/enum_not_supported.rs:4:6 + | +4 | enum MyEnum { + | ^^^^^^ diff --git a/filecaster/tests/ui/invalid_attr.rs b/filecaster/tests/ui/invalid_attr.rs deleted file mode 100644 index 5dc332f..0000000 --- a/filecaster/tests/ui/invalid_attr.rs +++ /dev/null @@ -1,9 +0,0 @@ -use filecaster::FromFile; - -#[derive(FromFile)] -struct MyStruct { - #[from_file(unknown)] - field: i32, -} - -fn main() {} diff --git a/filecaster/tests/ui/tuple_struct_not_supported.stderr b/filecaster/tests/ui/tuple_struct_not_supported.stderr new file mode 100644 index 0000000..5b42657 --- /dev/null +++ b/filecaster/tests/ui/tuple_struct_not_supported.stderr @@ -0,0 +1,6 @@ +error: FromFile only works on structs with *named* fields. + Tuple structs and unit structs are not supported. + --> tests/ui/tuple_struct_not_supported.rs:4:8 + | +4 | struct MyTuple(i32, String); + | ^^^^^^^