Stranger6667 / jsonschema-experimental

MIT License
2 stars 1 forks source link

fix: Resolve lifetime issue with parameter type J in iter_errors function #3

Open TieWay59 opened 3 months ago

TieWay59 commented 3 months ago

Description: When compiling the code, the compiler reports that the parameter type J may not have a long enough lifetime and needs to satisfy the 'static lifetime. This is because the function iter_errors returns a ValidationErrorIter containing a 'static lifetime, while the parameters schema and instance are of type &'s J and &'i J respectively, and their lifetimes 's and 'i may not be long enough to cover the 'static lifetime requirement.

Solution: To resolve this issue, we can add an explicit lifetime bound to the generic type J, ensuring it has a 'static lifetime. We can modify the function signature as follows:

pub async fn iter_errors<'s, 'i, J: Json + 'static>(
    schema: &'s J,
    instance: &'i J,
) -> ValidationErrorIter<'static, 'i, J> {
    try_iter_errors(schema, instance)
        .await
        .expect("Invalid schema")
}
TieWay59 commented 3 months ago

Hi @Stranger6667, feel free to close it if this is not the desired fix.