Skip to main content

Crate varchain

Crate varchain 

Source
Expand description

varchain is an async-only, zero-runtime-dependency crate for looking up variables from a chain of sources.

§Core Concepts

  • Resolved: The result of a lookup from a single source (Found or Pass).
  • Source: A trait for objects that can resolve a key to a Resolved value.
  • Scope: A collection of sources queried in order.
  • lookup: The primary function to query a key from a Scope.

§Example

use varchain::{Scope, Resolved, Source};
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("key1".to_string(), "value1".to_string());

let scope = Scope::new()
    .push(map); // HashMap impls Source

assert_eq!(scope.lookup("key1").await, Some("value1".to_string()));
assert_eq!(scope.lookup("key2").await, None);

Structs§

Scope
A chain of sources to be queried in order.

Enums§

Resolved
The result of resolving a key from a Source.

Traits§

Source
A source capable of looking up a variable by key.

Functions§

lookup
Looks up a key in the given scope.

Type Aliases§

SourceFuture
A future returned by a source lookup.