[][src]Struct kettle::Project

pub struct Project { /* fields omitted */ }

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.

Implementations

impl Project[src]

pub const fn init(
    project_name: &'static str,
    config_name: Option<&'static str>
) -> Self
[src]

Initializes your project for use throughout your app. Easily set as a constant so you only have to declare it once.

Example

use kettle::Project;

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

// or...

pub const fn app() {
    Project::init("app_name", Some("settings.ini"));
}

pub fn cache_dir(&self) -> PathBuf[src]

PathBuf for project's cache directory

Example

let cache_dir = APP.cache_dir();

pub fn config_dir(&self) -> PathBuf[src]

PathBuf for project's config directory

Example

let config_dir = APP.config_dir();

pub fn data_dir(&self) -> PathBuf[src]

PathBuf for project's data directory

Example

let data_dir = APP.data_dir();

pub fn data_local_dir(&self) -> PathBuf[src]

PathBuf for project's local data directory

Example

let data_local_dir = APP.data_local_dir();

pub fn preference_dir(&self) -> PathBuf[src]

PathBuf for project's preference directory

Example

let preference_dir = APP.preference_dir();

pub fn config_file(&self) -> PathBuf[src]

PathBuf for project's config file. If no name is provided during init, it will default to 'config'

Example

let config_file = APP.config_file();

pub fn config_set(
    &self,
    key: &'static str,
    value: Option<&'static str>
) -> Result<(), KettleError>
[src]

Set config key and value. Creates config file if it does not exist.

Example

APP.config_set("default-view", Some("vertical"))
APP.config_set("default-template", None)

If value is set to None, then key field is deleted from the file. Returns Err if unable to write config file.

pub fn config_section_set<S: Into<String>>(
    &self,
    section: S,
    key: &'static str,
    value: Option<&'static str>
) -> Result<(), KettleError>
[src]

Set config key and value for a specific section. Creates config file if it does not exist.

Example

APP.config_section_set("admin", "default-view", Some("vertical"))
APP.config_section_set("user.bob", "default-template", None)

If value is set to None, then key field is deleted from the file. If section is empty upon deletion, the section is deleted as well. Returns Err if unable to write config file.

pub fn config_get(&self, key: &str) -> Result<Option<String>, KettleError>[src]

Get config key's value and read it as a String.

Example

APP.config_get("default-view");

Returns Ok(None) if key does not exist or if field is blank. Returns Err if unable to read config file.

pub fn config_section_get<S: Into<String>>(
    &self,
    section: S,
    key: &str
) -> Result<Option<String>, KettleError>
[src]

Get config key's value from a specific section and read it as a String.

Example

APP.config_section_get("user.bob", "default-view");

Returns Ok(None) if key does not exist or if field is blank. Returns Err if unable to read config file.

Trait Implementations

impl Debug for Project[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,