mirror of
https://github.com/kristoferssolo/filecaster.git
synced 2025-10-21 19:00:34 +00:00
refactor: add better messages
This commit is contained in:
parent
c4cf6aa25b
commit
e20000513a
46
Cargo.lock
generated
46
Cargo.lock
generated
@ -58,6 +58,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"toml",
|
||||
"trybuild",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -87,6 +88,12 @@ dependencies = [
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.4"
|
||||
@ -281,6 +288,12 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-triple"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.20.0"
|
||||
@ -294,6 +307,15 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.9.2"
|
||||
@ -333,6 +355,21 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
|
||||
|
||||
[[package]]
|
||||
name = "trybuild"
|
||||
version = "1.0.110"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32e257d7246e7a9fd015fb0b28b330a8d4142151a33f03e6a497754f4b1f6a8e"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"target-triple",
|
||||
"termcolor",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
@ -348,6 +385,15 @@ dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
|
||||
@ -12,6 +12,7 @@ claims = "0.8"
|
||||
serde_json = "1.0"
|
||||
tempfile = "3.10"
|
||||
toml = "0.9"
|
||||
trybuild = "1.0"
|
||||
|
||||
[workspace.lints.clippy]
|
||||
pedantic = "warn"
|
||||
|
||||
@ -60,12 +60,14 @@ fn extract_named_fields(input: &DeriveInput) -> Result<&FieldsNamed> {
|
||||
Fields::Named(fields) => Ok(fields),
|
||||
_ => Err(Error::new_spanned(
|
||||
&input.ident,
|
||||
"FromFile can only be derived for structs with named fields",
|
||||
r#"FromFile only works on structs with *named* fields.
|
||||
Tuple structs and unit structs are not supported."#,
|
||||
)),
|
||||
},
|
||||
_ => Err(Error::new_spanned(
|
||||
&input.ident,
|
||||
"FromFile can only be derived for structs",
|
||||
r#"FromFile only works on structs.
|
||||
Enums are not supported."#,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,3 +28,4 @@ merge = { workspace = true, optional = true }
|
||||
serde_json.workspace = true
|
||||
tempfile.workspace = true
|
||||
toml.workspace = true
|
||||
trybuild.workspace = true
|
||||
|
||||
7
filecaster/tests/ui.rs
Normal file
7
filecaster/tests/ui.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use trybuild::TestCases;
|
||||
|
||||
#[test]
|
||||
fn ui() {
|
||||
let t = TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
}
|
||||
9
filecaster/tests/ui/enum_not_supported.rs
Normal file
9
filecaster/tests/ui/enum_not_supported.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use filecaster::FromFile;
|
||||
|
||||
#[derive(FromFile)]
|
||||
enum MyEnum {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
9
filecaster/tests/ui/invalid_attr.rs
Normal file
9
filecaster/tests/ui/invalid_attr.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use filecaster::FromFile;
|
||||
|
||||
#[derive(FromFile)]
|
||||
struct MyStruct {
|
||||
#[from_file(unknown)]
|
||||
field: i32,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
6
filecaster/tests/ui/tuple_struct_not_supported.rs
Normal file
6
filecaster/tests/ui/tuple_struct_not_supported.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use filecaster::FromFile;
|
||||
|
||||
#[derive(FromFile)]
|
||||
struct MyTuple(i32, String);
|
||||
|
||||
fn main() {}
|
||||
Loading…
Reference in New Issue
Block a user