Module Ambient_context_core.Storage

Storage implementation.

There is a singleton storage for a given program, responsible for providing ambient context to the rest of the program.

type t = {
  1. name : string;
  2. get_context : unit -> Context.t;
  3. with_context : 'a. Context.t -> (unit -> 'a) -> 'a;
}

Storage type

val name : t -> string

Name of the storage implementation.

val get_context : t -> Context.t

Get the context from the current storage, or Hmap.empty if there is no ambient context.

val with_context : t -> Context.t -> (unit -> 'a) -> 'a

with_context storage ctx f calls f() in an ambient context in which get_context() will return ctx. Once f() returns, the storage is reset to its previous value.

val get : t -> 'a Context.key -> 'a option

Get the ambient context and then look up k in it

val with_key_bound_to : t -> 'a Hmap.key -> 'a -> (unit -> 'b) -> 'b

with_key_bound_to storage k v f calls f() in a context updated to have k map to v.

val with_key_unbound : t -> 'a Hmap.key -> (unit -> 'b) -> 'b

with_key_unbound storage k f calls f() in a context updated to have k bound to no value.