Skip to main content

Module current

Module current 

Source
Expand description

Task-local “current” TypeSchemaRegistry handle.

This module exposes an ambient registry that is pushed by Runtime’s execution entry points and consumed by free functions that previously reached for the process-global STDLIB_SCHEMA_REGISTRY / NEXT_SCHEMA_ID statics. The scoping is three-layered to cover both async and synchronous entry points, with a process-wide default as the final fallback:

  1. Task-local (CURRENT_SCHEMA_REGISTRY) — survives task migration across tokio worker threads, so any descendant .await in a Shape execution future inherits the registry automatically.
  2. Thread-local (SYNC_CURRENT_SCHEMA_REGISTRY) — fallback for synchronous entry points (CLI, tests, REPL one-shots) that are not running under a tokio task. A SyncRegistryScope RAII guard pushes/pops the value so nested Runtimes on one thread compose correctly.
  3. Process-wide default (DEFAULT_SCHEMA_REGISTRY) — a single stdlib-populated registry shared by scopeless callers. Preserves the pre-B1.7 semantic that every caller sees some registry: ad-hoc tooling, static initialisers, and unit tests that don’t install a scope all share this handle instead of being forced to panic or observe None.

Mirrors the B5 shape_value::shape_graph_current::DEFAULT_SHAPE_TABLE pattern that retired the legacy GLOBAL_SHAPE_TABLE static.

Lookup order: task-local → thread-local → process default. Both current_registry and try_current_registry always return a usable handle; callers never need to branch on None or on a panic any more. Scoped callers (installed by Runtime) still get per-VM isolation, which was the original B1 goal.

Structs§

SyncRegistryScope
RAII guard that installs a registry on the thread-local slot for the lifetime of the guard.

Functions§

current_registry
Return a handle to the current ambient TypeSchemaRegistry.
default_registry
Return the process-wide default schema-registry handle.
try_current_registry
Alias for current_registry returning Option for historical API compatibility.
with_async_scope
Run fut with registry installed as the task-local current registry.