Skip to content
lsdocs plugin SDK API

lsdocs_plugin_sdk::config #

Reading a plugin's settings from the site's .config/ directory.

The host says where .config/ is (ConfigInfo); what a plugin keeps there, and in what format, is its own business. The recommended layout is <vendor>/<name>/, name being the plugin's name in the site config, so that two instances of a plugin keep separate settings: recommended builds such a path for lsdocs' own plugins, and toml_file reads one TOML file. A plugin registers a loader with Plugin::settings; it runs once, at initialize.

struct Loaded #

pub struct Loaded

A plugin's settings, as its loader read them.

Trait implementations

field settings #

pub settings: Value

The settings, as the plugin wants them (null for none).

field files #

pub files: Vec<String>

The files read (relative to .config/, or absolute), including ones looked for and not found: the host's cache keys cover them.

function recommended #

pub fn recommended(config: &ConfigInfo, file: &str) -> String

lsdocs/<name>/<file>: where lsdocs' own plugins keep file.

function toml_file #

pub fn toml_file(config: &ConfigInfo, relative: &str) -> Result<Loaded, String>

Reads <.config>/<relative> as TOML. A missing file is no settings (null), still listed in Loaded::files; a file that is not TOML is an error naming it.

function settings_toml #

pub fn settings_toml(config: &ConfigInfo) -> Result<Loaded, String>

lsdocs' own plugins' loader: lsdocs/<name>/settings.toml, as TOML.

function settings_toml_as #

pub fn settings_toml_as<T: DeserializeOwned + Default>(
    config: &ConfigInfo,
) -> Result<Loaded, String>

settings_toml, checked against T (unknown or bad keys are an error naming the file): a loader for plugins with a settings type.

enum Kind #

pub enum Kind

What a setting's value must be (see settings_toml_keys).

Trait implementations

variant Bool #

Bool

true or false.

variant Integer #

Integer

A whole number.

variant String #

String

A string.

variant Array #

Array

An array.

variant Table #

Table

A table.

variant Any #

Any

Anything.

function settings_toml_keys #

pub fn settings_toml_keys(config: &ConfigInfo, keys: &[(&str, Kind)]) -> Result<Loaded, String>

settings_toml, with only keys allowed, each of its kind (any other key, or a value of another kind, is an error naming the file): a loader for plugins reading a few keys.

function parse #

pub fn parse<T: DeserializeOwned + Default>(settings: &Value, file: &str) -> Result<T, String>

Reads settings (as a loader returned them) into a type, null being its default; an unknown or bad key is an error naming file.