Skip to content

Why does validate requires 'static for the operation parameter?Β #40

@guidomb

Description

@guidomb

Hi, first of all I want to clarify that I'm not an experienced Rust developer and therefore I may be getting lifetimes wrong. That being said, I don't understand why validate requires the operation argument to be 'static. I assume that schema is required to be 'static basically for convenience and to avoid having to bubble up lifetimes everywhere, which kind of makes sense because probably most use cases require the schema to be alive through out the entire program life-cycle. But I don't think that's the case for queries.

The particular use case I'm working on requires me to parse a query, do some computation and then return the result of such computation (which does not hold any reference to the query) and throwing away the query when the function that parses it terminates. To exemplify this

fn do_something_with_query(&self, query_file_path: &str) -> Result<ComputatioOutput, SomeErrorType> {
    let raw_query = read_to_string(query_file_path)?;
    let query = parse_query(query)? // let's assume that error types are automagically converted to SomeErrorType
    let validation_errors = validate(&self.schema, &query, &self.validation_rules)
    if validation_errors.is_empty() {
        Ok(/* do some computation with the query */)
    } else {
        Err(/* SOME ERROR*/)
    }
}

Sure I could call into_static() in the query but that "feels" wrong and also in the real use case now I need to require that al query documents are static (I have other function that perform computation pieces and require a reference to the query).

Am I correct o what did I miss?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions