Struct languages_rs::Config [−][src]
Implementations
impl Config
[src]
pub fn new(
directory: &str,
format: Format,
languages: Vec<&str>
) -> Result<Self>
[src]
directory: &str,
format: Format,
languages: Vec<&str>
) -> Result<Self>
Create a new configuration.
Example
ⓘ
use languages_rs::{Config, Format}; let config: Config = match Config::new("languages", Format::Json, vec!["en"]) { Ok(config) => config, Err(e) => { eprintln!("Error: {}", e); return; }, };
pub fn default() -> Result<Self>
[src]
Get the default configuration.
Default
{
"directory": "languages/",
"format": "JSON",
"languages": []
Example
ⓘ
use languages_rs::Config; let config: Config = match Config::default() { Ok(config) => config, Err(e) => { eprintln!("Error: {}", e); return; }, };
pub fn get_directory(&self) -> String
[src]
Get the languages directory.
Example
ⓘ
use std::{env, path}; use languages_rs::Config; let config = Config::default().unwrap(); assert_eq!( config.get_directory(), format!( "{}{}languages", env::current_dir().unwrap().display(), path::MAIN_SEPARATOR, ), );
pub fn set_directory(&mut self, new_directory: &str) -> Result<()>
[src]
Change the languages directory.
Example
ⓘ
use std::env; use languages_rs::Config; let mut config = Config::default().unwrap(); assert!(config.set_directory("languages").is_ok());
pub fn get_format(&self) -> Format
[src]
Get the format files.
Example
ⓘ
use languages_rs::{Config, Format}; let config = Config::default().unwrap(); assert_eq!(config.get_format(), Format::Json);
pub fn change_format(&mut self, new_format: Format)
[src]
Change the format files.
Example
ⓘ
use languages_rs::{Config, Format}; let mut config = Config::default().unwrap(); assert!(config.get_format().is_json()); config.change_format(Format::Toml); assert!(config.get_format().is_toml());
pub fn get_languages(&self) -> Vec<String>
[src]
Get the availables languages.
Example
ⓘ
use languages_rs::Config; let config = Config::default().unwrap(); assert_eq!(config.get_languages(), Vec::<String>::new());
pub fn add_language(&mut self, language: String) -> Result<()>
[src]
Add a new language to the languages list if it does not exist.
Example
ⓘ
use languages_rs::Config; let mut config = Config::default().unwrap(); assert_eq!(config.get_languages(), Vec::<String>::new()); assert!(config.add_language(String::from("en")).is_ok()); assert_eq!(config.get_languages(), vec![String::from("en")]);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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>,