pub trait PluginOption {
type Value: FromStr;
const NAME: &'static str;
const DOC: &'static str;
const DEFAULT: &'static str;
const KIND: OptionKind;
}Expand description
A plugin-defined scalar option — a typed view over the config
register/read wire (slice PH7.10b). Implement via #[derive(PluginOption)]
on a newtype over bool / i64 / String; #[option(default = "...")] is
required, #[option(name = "...")] defaults to the kebab-cased type name.
For structured (record / list / enum) options use shape::ConfigShape
instead.
It is WIT-agnostic (approach A): the derive only supplies these constants
plus the value type. The plugin makes the config.register-option /
config.get-option WIT calls itself, mapping OptionKind to the generated
option-type (config below stands in for a plugin’s generated bindings):
use lattice_plugin_sdk::{OptionKind, PluginOption, parse_option};
/// How many things the plugin tracks.
#[derive(PluginOption)]
#[option(name = "myplugin.count", default = "3")]
struct Count(i64);
// The one per-plugin mapping to the generated WIT enum.
fn wit_ty(kind: OptionKind) -> config::OptionType {
match kind {
OptionKind::Boolean => config::OptionType::Boolean,
OptionKind::Integer => config::OptionType::Integer,
OptionKind::String => config::OptionType::String,
}
}
config::register_option(Count::NAME, wit_ty(Count::KIND), Count::DEFAULT, Count::DOC);
let value: i64 = parse_option::<Count>(&config::get_option(Count::NAME).unwrap()).unwrap();
assert_eq!(value, 5);
assert_eq!(Count::NAME, "myplugin.count");
assert_eq!(Count::KIND, OptionKind::Integer);
assert_eq!(Count::DOC, "How many things the plugin tracks.");Required Associated Constants§
Sourceconst NAME: &'static str
const NAME: &'static str
The option’s registry name (matched by :set, shown in :describe-option).
Sourceconst DEFAULT: &'static str
const DEFAULT: &'static str
The initial value as a string (parsed host-side via the native OptionType).
Sourceconst KIND: OptionKind
const KIND: OptionKind
The value type — maps to the WIT option-type when registering.
Required Associated Types§
Sourcetype Value: FromStr
type Value: FromStr
The Rust value type (bool / i64 / String), parsed from a
get-option string via parse_option.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".