yassun7010 / serde_valid

JSON Schema based validation tool using serde.
MIT License
46 stars 10 forks source link

Derive of Validate does not use fully-qualified Result enums #8

Closed nickjknight closed 1 year ago

nickjknight commented 1 year ago

If a pub struct Ok(string) is defined in the same file as deriving Validate on a struct, the derivation will fail to compile due to attempting to return the new Ok struct instead of the std::result::Result::Ok. The same issue is true with Err().

Suggested fix would be to fully qualify uses of Ok and Err wherever needed to fix this (in the impl definition?).

Here's an example of code that fails to compile with this issue (same happens if "Ok" is "Err"):

use serde_valid::Validate;

#[derive(Debug, Validate)]
pub struct Other {
    #[validate(minimum = 20)]
    number: i32,
}

pub struct Ok(String);
nickjknight commented 1 year ago

I tried fixing this, but it seems this might actually originate in proc-macro-error-attr (found via -Z macro-backtrace), so this might not be your problem. If you can think of a way to make this work, that'd be nice so I'm going to leave this open for now.

yassun7010 commented 1 year ago

With reference to serde, it seems that the Result type is used this way within crate.

Maybe other types in std::prelude are likely to have conflicts.

I don't know if there is enough need to support this.

yassun7010 commented 1 year ago

Once closed unless I find other user for this issue.