INNER CODE UNIT · Rust

get_set_cached

graphql-rust/graphql-client · graphql_client_codegen/src/lib.rs:50

fn get_set_cached<T: Clone>(
    cache: &CacheMap<T>,
    key: &std::path::Path,
    value_func: impl FnOnce() -> T,
) -> T {
    let mut lock = cache.lock().expect("cache is poisoned");
    lock.entry(key.into()).or_insert_with(value_func).clone()
}

fn query_document(query_string: &str) -> Result<QueryDocument, BoxError> {
    let document = graphql_parser::parse_query(query_string)
        .map_err(|err| GeneralError(format!("Query parser error: {}", err)))?
        .into_static();
    Ok(document)
}

fn get_set_query_from_file(query_path: &std::path::Path) -> (String, QueryDocument) {
    get_set_cached(&QUERY_CACHE, query_path, || {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…