[][src]Crate kettle

kettle is a small library which provides simple cross-platform access to project specific config, cache, data, etc. directories for applications running on Linux/macOS/Windows. It also includes an ini based config file which can be easily used for application settings.

This crate utilizes the dirs crate and re-exports it for easy access to non-application directories.

Usage

use kettle::Project;

pub const APP: Project = Project::init("app_name", None);

fn main() {
    let config_dir = APP.config_dir();
    let cache_dir = APP.cache_dir();
    let data_dir = APP.data_dir();

    APP.config_set("default_view", Some("vertical"));
    APP.config_section_set("admin", "default_view", Some("horizontal"));
    APP.config_set("key with spaces", None);

    let default_view = APP.config_get("default_view").unwrap();
    let admin_view = APP.config_section_get("admin", "default_view").unwrap();
    let spaces_key = APP.config_get("key with spaces").unwrap();

    assert_eq!(default_view, Some("vertical".to_string()));
    assert_eq!(admin_view, Some("horizontal".to_string()));
    assert_eq!(spaces_key, None);

    // Default config file name is 'config' and is saved in the respective config directory.
    // Config file name can be changed during initialization.
    // e.g. `Project::init("app_name", "settings.ini");
}

Modules

dirs

Aliases to dirs crate.

Structs

Project

The Project struct is used to access your directories and config throughout your project. It allows you to set the project name and an optional config file name. See init() for more info.