summaryrefslogtreecommitdiffstats
path: root/libimagrt
diff options
context:
space:
mode:
authorAndre Bogus <bogusandre@gmail.com>2016-05-03 23:10:32 +0200
committerAndre Bogus <bogusandre@gmail.com>2016-05-13 22:27:53 +0200
commit981707c9c959668e09f83926f6dafa296e84ebf0 (patch)
treeb534d8acea0c0a7d0b27c81963fe62e075f1709b /libimagrt
parent7a46df312549d6bf97b6ebcb40599061c57ca55e (diff)
more style adaptations
again following clippy
Diffstat (limited to 'libimagrt')
-rw-r--r--libimagrt/src/configuration.rs93
-rw-r--r--libimagrt/src/error.rs8
-rw-r--r--libimagrt/src/runtime.rs20
3 files changed, 48 insertions, 73 deletions
diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs
index eb199a53..15b94e09 100644
--- a/libimagrt/src/configuration.rs
+++ b/libimagrt/src/configuration.rs
@@ -12,17 +12,13 @@ pub mod error {
use std::fmt::{Display, Formatter};
use std::fmt::Error as FmtError;
- /**
- * The kind of an error
- */
+ /// The kind of an error
#[derive(Clone, Debug, PartialEq)]
pub enum ConfigErrorKind {
NoConfigFileFound,
}
- /**
- * Configuration error type
- */
+ /// Configuration error type
#[derive(Debug)]
pub struct ConfigError {
kind: ConfigErrorKind,
@@ -31,9 +27,7 @@ pub mod error {
impl ConfigError {
- /**
- * Instantiate a new ConfigError, optionally with cause
- */
+ /// Instantiate a new `ConfigError`, optionally with cause
pub fn new(kind: ConfigErrorKind, cause: Option<Box<Error>>) -> ConfigError {
ConfigError {
kind: kind,
@@ -41,16 +35,12 @@ pub mod error {
}
}
- /**
- * get the Kind of the Error
- */
+ ///get the Kind of the Error
pub fn err_type(&self) -> ConfigErrorKind {
self.kind.clone()
}
- /**
- * Get the string, the ConfigError can be described with
- */
+ /// Get the string, the `ConfigError` can be described with
pub fn as_str(e: &ConfigError) -> &'static str {
match e.err_type() {
ConfigErrorKind::NoConfigFileFound => "No config file found",
@@ -86,51 +76,39 @@ use self::error::{ConfigError, ConfigErrorKind};
/**
- * Result type of this module. Either T or ConfigError
+ * Result type of this module. Either `T` or `ConfigError`
*/
pub type Result<T> = RResult<T, ConfigError>;
-/**
- * Configuration object
- *
- * Holds all config variables which are globally available plus the configuration object from the
- * config parser, which can be accessed.
- */
+/// `Configuration` object
+///
+/// Holds all config variables which are globally available plus the configuration object from the
+/// config parser, which can be accessed.
#[derive(Debug)]
pub struct Configuration {
- /**
- * The plain configuration object for direct access if necessary
- */
+ /// The plain configuration object for direct access if necessary
config: Value,
- /**
- * The verbosity the program should run with
- */
+ /// The verbosity the program should run with
verbosity: bool,
- /**
- * The editor which should be used
- */
+ /// The editor which should be used
editor: Option<String>,
- /**
- * The options the editor should get when opening some file
- */
+ ///The options the editor should get when opening some file
editor_opts: String,
}
impl Configuration {
- /**
- * Get a new configuration object.
- *
- * The passed runtimepath is used for searching the configuration file, whereas several file
- * names are tested. If that does not work, the home directory and the XDG basedir are tested
- * with all variants.
- *
- * If that doesn't work either, an error is returned.
- */
+ /// Get a new configuration object.
+ ///
+ /// The passed runtimepath is used for searching the configuration file, whereas several file
+ /// names are tested. If that does not work, the home directory and the XDG basedir are tested
+ /// with all variants.
+ ///
+ /// If that doesn't work either, an error is returned.
pub fn new(rtp: &PathBuf) -> Result<Configuration> {
fetch_config(&rtp).map(|cfg| {
let verbosity = get_verbosity(&cfg);
@@ -161,8 +139,8 @@ impl Configuration {
}
pub fn store_config(&self) -> Option<&Value> {
- match &self.config {
- &Value::Table(ref tabl) => tabl.get("store"),
+ match self.config {
+ Value::Table(ref tabl) => tabl.get("store"),
_ => None,
}
}
@@ -179,27 +157,26 @@ impl Deref for Configuration {
}
fn get_verbosity(v: &Value) -> bool {
- match v {
- &Value::Table(ref t) => t.get("verbose")
- .map(|v| match v { &Value::Boolean(b) => b, _ => false, })
- .unwrap_or(false),
+ match *v {
+ Value::Table(ref t) => t.get("verbose")
+ .map_or(false, |v| match *v { Value::Boolean(b) => b, _ => false, }),
_ => false,
}
}
fn get_editor(v: &Value) -> Option<String> {
- match v {
- &Value::Table(ref t) => t.get("editor")
- .and_then(|v| match v { &Value::String(ref s) => Some(s.clone()), _ => None, }),
+ match *v {
+ Value::Table(ref t) => t.get("editor")
+ .and_then(|v| match *v { Value::String(ref s) => Some(s.clone()), _ => None, }),
_ => None,
}
}
fn get_editor_opts(v: &Value) -> String {
- match v {
- &Value::Table(ref t) => t.get("editor-opts")
- .and_then(|v| match v { &Value::String(ref s) => Some(s.clone()), _ => None, })
- .unwrap_or(String::new()),
+ match *v {
+ Value::Table(ref t) => t.get("editor-opts")
+ .and_then(|v| match *v { Value::String(ref s) => Some(s.clone()), _ => None, })
+ .unwrap_or_default(),
_ => String::new(),
}
}
@@ -224,7 +201,7 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
let variants = vec!["config", "config.toml", "imagrc", "imagrc.toml"];
let modifier = |base: &PathBuf, v: &'static str| {
let mut base = base.clone();
- base.push(format!("{}", v));
+ base.push(String::from(v));
base
};
@@ -268,6 +245,6 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
.filter(|loaded| loaded.is_some())
.nth(0)
.map(|inner| Value::Table(inner.unwrap()))
- .ok_or(ConfigError::new(ConfigErrorKind::NoConfigFileFound, None))
+ .ok_or_else(|| ConfigError::new(ConfigErrorKind::NoConfigFileFound, None))
}
diff --git a/libimagrt/src/error.rs b/libimagrt/src/error.rs
index 5ad5ea3d..ca343ede 100644
--- a/libimagrt/src/error.rs
+++ b/libimagrt/src/error.rs
@@ -31,10 +31,10 @@ impl RuntimeError {
}
fn runtime_error_kind_as_str(e: &RuntimeErrorKind) -> &'static str {
- match e {
- &RuntimeErrorKind::Instantiate => "Could not instantiate",
- &RuntimeErrorKind::IOError => "IO Error",
- &RuntimeErrorKind::ProcessExitFailure => "Process exited with failure",
+ match *e {
+ RuntimeErrorKind::Instantiate => "Could not instantiate",
+ RuntimeErrorKind::IOError => "IO Error",
+ RuntimeErrorKind::ProcessExitFailure => "Process exited with failure",
}
}
diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs
index 7319958f..c67422cc 100644
--- a/libimagrt/src/runtime.rs
+++ b/libimagrt/src/runtime.rs
@@ -55,22 +55,20 @@ impl<'a> Runtime<'a> {
Runtime::init_logger(is_debugging, is_verbose);
let rtp : PathBuf = matches.value_of("runtimepath")
- .map(PathBuf::from)
- .unwrap_or_else(|| {
+ .map_or_else(|| {
env::var("HOME")
.map(PathBuf::from)
.map(|mut p| { p.push(".imag"); p})
.unwrap_or_else(|_| {
panic!("You seem to be $HOME-less. Please get a $HOME before using this software. We are sorry for you and hope you have some accommodation anyways.");
})
- });
+ }, PathBuf::from);
let storepath = matches.value_of("storepath")
- .map(PathBuf::from)
- .unwrap_or({
+ .map_or_else(|| {
let mut spath = rtp.clone();
spath.push("store");
spath
- });
+ }, PathBuf::from);
let cfg = Configuration::new(&rtp);
let cfg = if cfg.is_err() {
@@ -87,9 +85,9 @@ impl<'a> Runtime<'a> {
};
let store_config = {
- match &cfg {
- &Some(ref c) => c.store_config().map(|c| c.clone()),
- &None => None,
+ match cfg {
+ Some(ref c) => c.store_config().cloned(),
+ None => None,
}
};
@@ -268,8 +266,8 @@ impl<'a> Runtime<'a> {
.value_of("editor")
.map(String::from)
.or({
- match &self.configuration {
- &Some(ref c) => c.editor().map(|s| s.clone()),
+ match self.configuration {
+ Some(ref c) => c.editor().cloned(),
_ => None,
}
})