Expand description
What an adapter declares about itself: which port it implements, its kind string, and the shape of its options.
An adapter owns its configuration (ADR 0001). It writes one struct, derives
AdapterConfig on it, and from that single declaration the composition
root gets everything it renders: the editor JSON schema, the Reference
option tables, the designer’s forms, and the environment variables that
override the adapter’s secrets. Nothing in the kernel or the config layer
names the adapter.
use kernel::{AdapterConfig, Options, Port, Secret};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Where the documents go.
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
struct DemoConfig {
/// The cluster URL.
url: Secret,
/// Documents per request.
#[serde(default = "default_batch")]
batch_size: u32,
}
fn default_batch() -> u32 { 1000 }
impl AdapterConfig for DemoConfig {
const PORT: Port = Port::Sink;
const KIND: &'static str = "demo";
fn example() -> Self {
Self { url: Secret::Value("https://search:9200".into()), batch_size: 500 }
}
}
let description = DemoConfig::description();
assert_eq!(description.kind, "demo");
// Every `Secret` field gets an override variable, named per entry.
let vars: Vec<String> = description.override_vars("primary").collect();
assert_eq!(vars, ["PRIMARY_DEMO_URL"]);
let mut options = Options::empty();
options.insert("url", "https://other:9200");
let config = DemoConfig::from_options(options).unwrap();
assert_eq!(config.batch_size, 1000);Structs§
- Adapter
Description - The rendered facts about one adapter’s options: the JSON schema (draft-07; doc comments as descriptions, serde defaults as defaults), an example, and the field paths that accept an override variable.
Enums§
- Port
- The three contracts the engine drives. Every adapter implements exactly one.
Constants§
- SECRET_
MARKER - The schema-property marker a
Secretplants so a description can find the fields that take an override variable.
Traits§
- Adapter
Config - An adapter’s configuration type: its port, its kind, and an example.
Functions§
- override_
var - The environment variable that overrides one option of one port entry:
<ENTRY>_<KIND>_<FIELD>, uppercased, nested path segments joined with_.