[−][src]Struct kettle::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.
Implementations
impl Project
[src]
pub const fn init(
project_name: &'static str,
config_name: Option<&'static str>
) -> Self
[src]
project_name: &'static str,
config_name: Option<&'static str>
) -> Self
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]
pub fn config_dir(&self) -> PathBuf
[src]
pub fn data_dir(&self) -> PathBuf
[src]
pub fn data_local_dir(&self) -> PathBuf
[src]
pub fn preference_dir(&self) -> PathBuf
[src]
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]
&self,
key: &'static str,
value: Option<&'static str>
) -> Result<(), KettleError>
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]
&self,
section: S,
key: &'static str,
value: Option<&'static str>
) -> Result<(), KettleError>
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]
&self,
section: S,
key: &str
) -> Result<Option<String>, KettleError>
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
Auto Trait Implementations
impl RefUnwindSafe for Project
[src]
impl Send for Project
[src]
impl Sync for Project
[src]
impl Unpin for Project
[src]
impl UnwindSafe for Project
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,