Skip to main content

Module adapters

Module adapters 

Source
Expand description

Read config formats owned by other programs as HOCON.

Each adapter returns a fully resolved Config you place under your own document with Config::with_fallback, so a ${...} can reach into it:

let base = hocon::adapters::env::load(hocon::adapters::env::Options {
    prefix: "APP_".into(),
    ..Default::default()
})?;
let cfg = hocon::parse_string_with_options(src, opts_without_resolution)?;
let merged = cfg.with_fallback(&base).resolve(Default::default())?;

Deferring resolution matters: the plain parse resolves as it goes, so a ${...} aimed at the fallback would fail before the fallback is attached.

Every adapter is behind a cargo feature, so the crate’s default build still depends on indexmap alone. properties and env need nothing extra; jsonc, toml and yaml pull one crate each.

Foreign data stays data: a ${a.b} in an ingested value is literal text, never a reference (spec F0.2). Ingestion is AST-level — a document is decoded and turned into a value tree, never rendered to HOCON text.

See docs/specs/format-ingestion-mapping.md in the hocon scope.

Modules§

env
Environment variables, and .env files, as HOCON config.
jsonc
JSON with comments and trailing commas — the dialect VS Code and TypeScript use for their config files — as HOCON config.
properties
java.util.Properties files as HOCON config.
toml
TOML documents as HOCON config.
yaml
YAML documents as HOCON config.

Structs§

AdapterError
The error every adapter reports.