pub struct Config {
pub template: Template,
pub cookie: Option<String>,
pub editor: String,
pub config_dir: PathBuf,
}Expand description
Validated configuration.
Fields§
§template: TemplateThe parsed project path template.
The Advent of Code session cookie, if one is available.
editor: StringThe command launched by aoc code.
config_dir: PathBufThe directory the configuration was loaded from.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load(env: &Env) -> Result<(Self, Vec<Warning>), ConfigError>
pub fn load(env: &Env) -> Result<(Self, Vec<Warning>), ConfigError>
Loads and validates the configuration described by env.
Returns the configuration together with any non-fatal warnings, such as
unrecognised keys - a misspelled cookies: would otherwise silently
disable submission.
With no cookie in the environment or the file itself, the
COOKIE_FILE_NAME file in Env::config_dir is read as one. A cookie
file that exists but cannot be read is a warning rather than an error,
so it cannot stop aoc path, aoc code or any other command that
needs no cookie at all.
§Errors
Returns ConfigError if the file is missing, unreadable, not valid
YAML, or contains an invalid template_path.
Sourcepub fn from_yaml(
contents: &str,
env: &Env,
) -> Result<(Self, Vec<Warning>), ConfigError>
pub fn from_yaml( contents: &str, env: &Env, ) -> Result<(Self, Vec<Warning>), ConfigError>
Parses configuration from a YAML document, resolving paths and the
session cookie against env. Unlike Config::load, this does not
fall back to the cookie file.
§Errors
Returns ConfigError if the document is not valid YAML or the
template_path is not a valid template.