Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guidomb opened this issue Jun 28, 2022 · 0 comments
Open

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

guidomb opened this issue Jun 28, 2022 · 0 comments

Comments

@guidomb
Copy link

guidomb commented Jun 28, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant