Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub asbuilt: Option<String>,
    pub output: OutputConfig,
    pub docs: DocsConfig,
    pub theme: BTreeMap<String, ThemeColor>,
    pub externals: Vec<External>,
    pub sections: BTreeMap<String, Value>,
    pub path: Option<PathBuf>,
}
Expand description

The parsed asbuilt.toml.

Other top-level entries stay in sections, where a front-end’s table ([rust], say) waits to be deserialized with that front-end’s schema; Config::check_tables rejects any that names no front-end. Unknown keys inside [output] or an [[externals]] entry are rejected when parsing.

use asbuilt_core::Config;

let config: Config = r#"
[output]
path = "arch/model.c4"

[rust]
include_tests = false
"#
.parse()
.unwrap();

assert_eq!(config.output.path, "arch/model.c4");
assert!(config.sections.contains_key("rust"));

Fields§

§asbuilt: Option<String>

The asbuilt release this config and its model are written for, as cargo install --version takes it. Config::load_for checks it against the running release before reading anything else; None runs under any release.

§output: OutputConfig§docs: DocsConfig§theme: BTreeMap<String, ThemeColor>

[theme]: a color per element kind (container, component, bin, tests, examples, or an external kind), emitted as LikeC4 element styles so the diagrams come out in the consumer’s palette.

§externals: Vec<External>§sections: BTreeMap<String, Value>§path: Option<PathBuf>

Where this config was read from, for error messages. None for a config parsed from a string or defaulted.

Implementations§

Source§

impl Config

Source

pub fn light_theme(&self) -> BTreeMap<String, String>

The light color per themed kind, the emitter’s input.

Source§

impl Config

Source

pub fn load(root: &Path) -> Result<Self>

The config at root/asbuilt.toml, or the defaults when there is no such file.

Source

pub fn load_file(path: &Path) -> Result<Self>

A config from an explicit path (--config); a missing file is an error here, unlike Config::load.

Source

pub fn load_for( root: &Path, config_path: Option<&Path>, running: &str, ) -> Result<Self>

The config a binary at release running reads: config_path when given, else root/asbuilt.toml, else the defaults. The pin is checked against running before the rest of the file is deserialized, so a config written for another release fails on the version, not on a table or key this release does not know.

Source

pub fn file_path(&self) -> PathBuf

The file this config came from, for error messages: asbuilt.toml when it was parsed from a string or defaulted.

Source

pub fn check_tables(&self, frontends: &[&str]) -> Result<()>

Every top-level entry is asbuilt’s own or the table of one of frontends (by Frontend::name); the first that is neither is an error naming it as written.

Source

pub fn section<T: DeserializeOwned>(&self, name: &str) -> Result<Option<T>>

A front-end’s own table, deserialized with its schema. Ok(None) when the table is absent; a Config error naming the file when it is present and does not fit.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromStr for Config

Parsing alone: the pin’s place and shape are checked by the loaders, which know the file to name.

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.