lumeohq / xsd-parser-rs

A xsd/wsdl => rust code generator written in rust
Apache License 2.0
96 stars 34 forks source link

Compiler error in generated validation #71

Closed LeonidKrutovsky closed 4 years ago

LeonidKrutovsky commented 4 years ago

In generated file xsd/types.rs

// Type used to represent the numbers from 1 ,2 , 3,...
#[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)]
pub struct PositiveInteger (pub u32);

impl Validate for PositiveInteger {
    fn validate(&self) -> Result<(), String> { 
        if self.0 < "1".parse().unwrap() {
            return Err(format!("MinInclusive validation error: invalid value of 0! \nExpected: 0 >= 1.\nActual: 0 == {}", self.0));
        }
        Ok(())
    }
}

Compiler result:

error[E0283]: type annotations needed
   --> src/schema/types.rs:106:19
    |
106 |       if self.0 < "1".parse().unwrap() {
    |                   ^ cannot infer type for type `u32`
    |
    = note: cannot resolve `u32: std::cmp::PartialOrd<_>`