greyblake / nutype

Rust newtype with guarantees πŸ‡ΊπŸ‡¦ πŸ¦€
MIT License
1.4k stars 23 forks source link

validate with error with module path fails #186

Closed vic1707 closed 2 weeks ago

vic1707 commented 2 weeks ago

I don't know if the issue name is right or understandable sorry.

I found out that

#[nutype(validate(with = fs::exists, error = io::Error))]
struct File(PathBuf);

causes an error at the io::. I think the macro should support that.

Current workaround

use std::io::Error as IoError; 🀷

greyblake commented 2 weeks ago

Good catch! Thanks for reporting! I will fix that.

Though, I'd like to point, that the example above is not gonna work anyway because the function passed to with = should return Result<(), Error>. In case of fs::exists it returns Result<bool, Error>.

vic1707 commented 2 weeks ago

Yup I got that too, I made a separate function to check if it exists and is a file πŸ™ƒ When opening the issue I reverted to that state and forgot to check if it compiled since I was interested by the macro parsing 🀣 That's my bad

greyblake commented 2 weeks ago

Fixed in https://github.com/greyblake/nutype/pull/187