Struct languages_rs::Config[][src]

pub struct Config { /* fields omitted */ }

Implementations

impl Config[src]

pub fn new(
    directory: &str,
    format: Format,
    languages: Vec<&str>
) -> Result<Self>
[src]

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

impl Clone for Config[src]

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]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.