Remove unnecessary code
This commit removes some unnecessary code, such as an extra `String` clone, unnecessary `return` statements, and an inherent `to_string` function for the `Regex` wrapper. A double-quote character considered as a string literal by the compiler was also changed to a single-quote character, this time considered as a character by the compiler, for some optimization. Also a newline is added in order to improve code readablitiy.
This commit is contained in:
parent
3c960eaa35
commit
a8bafc072b
@ -87,6 +87,7 @@ macro_rules! decode_settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Representation of the software’s settings
|
/// Representation of the software’s settings
|
||||||
///
|
///
|
||||||
/// This struct represents all the settings the software has to follow
|
/// This struct represents all the settings the software has to follow
|
||||||
@ -334,7 +335,7 @@ impl Settings {
|
|||||||
pub fn apply(&self, s: String) -> std::result::Result<String, String> {
|
pub fn apply(&self, s: String) -> std::result::Result<String, String> {
|
||||||
// TODO Add Error handling
|
// TODO Add Error handling
|
||||||
let rules = self.update_rules().unwrap();
|
let rules = self.update_rules().unwrap();
|
||||||
let mut s = s.clone();
|
let mut s = s;
|
||||||
debug!("===============================================");
|
debug!("===============================================");
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
debug!(
|
debug!(
|
||||||
@ -379,7 +380,7 @@ impl FromStr for Settings {
|
|||||||
Ok(val) => Ok(val),
|
Ok(val) => Ok(val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Could not decode input {}: {}", s, e.to_string());
|
error!("Could not decode input {}: {}", s, e.to_string());
|
||||||
return Err(e);
|
Err(e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl Rule {
|
|||||||
|
|
||||||
impl From<String> for Rule {
|
impl From<String> for Rule {
|
||||||
fn from(source: String) -> Self {
|
fn from(source: String) -> Self {
|
||||||
let components: Vec<&str> = source.split_terminator(">").collect();
|
let components: Vec<&str> = source.split_terminator('>').collect();
|
||||||
Self {
|
Self {
|
||||||
from: Regex::new(components[0]),
|
from: Regex::new(components[0]),
|
||||||
to: String::from(components[1]),
|
to: String::from(components[1]),
|
||||||
|
@ -11,10 +11,6 @@ impl Regex {
|
|||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
self.0.as_str()
|
self.0.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
|
||||||
self.0.to_string()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
@ -39,7 +39,7 @@ pub fn read_file(path: &Path) -> Result<String> {
|
|||||||
match file.read_to_string(&mut content) {
|
match file.read_to_string(&mut content) {
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
error!("Could not read {}: {}", display, why.to_string());
|
error!("Could not read {}: {}", display, why.to_string());
|
||||||
return Err(why);
|
Err(why)
|
||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Content of {} read", display);
|
info!("Content of {} read", display);
|
||||||
|
Loading…
Reference in New Issue
Block a user