Run clippy lint

This commit is contained in:
Peltoche 2018-11-24 13:30:29 +01:00
parent 97fbdb63cb
commit 1f64ced9d9
No known key found for this signature in database
GPG key ID: CED68D0487156952
2 changed files with 51 additions and 54 deletions

View file

@ -27,7 +27,7 @@ pub struct Meta {
impl<'a> Core<'a> {
pub fn new(options: &'a Options) -> Core<'a> {
Core {
options: options,
options,
formatter: Formatter::new(),
}
}
@ -59,13 +59,13 @@ impl<'a> Core<'a> {
files.sort_unstable_by(sort_by_meta);
dirs.sort_unstable();
if files.len() > 0 {
self.print_long(&mut files);
if !files.is_empty() {
self.print_long(&files);
}
for dir in dirs {
let folder_metas = self.list_folder_content(dir);
if folder_metas.len() == 0 {
if folder_metas.is_empty() {
continue;
}
@ -114,7 +114,7 @@ impl<'a> Core<'a> {
}
// Skip the hidden files if the 'display_all' option is not set.
if name.unwrap().starts_with(".") && !self.options.display_all {
if name.unwrap().starts_with('.') && !self.options.display_all {
return None;
}
@ -160,22 +160,22 @@ impl<'a> Core<'a> {
path: path.to_path_buf(),
metadata: meta,
name: String::from(name.unwrap()),
user: user,
group: group,
symlink: symlink,
user,
group,
symlink,
size_value: size_parts[0].to_string(),
size_unit: size_parts[1].to_string(),
})
}
fn print_long(&self, metas: &Vec<Meta>) {
let max_user_length = self.detect_user_lenght(metas);
let max_group_length = self.detect_group_lenght(metas);
let (max_size_value_length, max_size_unit_length) = self.detect_size_lenghts(metas);
fn print_long(&self, metas: &[Meta]) {
let max_user_length = self.detect_user_lenght(&metas);
let max_group_length = self.detect_group_lenght(&metas);
let (max_size_value_length, max_size_unit_length) = self.detect_size_lenghts(&metas);
for meta in metas {
print!(
" {} {} {} {} {} {}\n",
println!(
" {} {} {} {} {} {}",
self.formatter.format_permissions(&meta),
self.formatter.format_user(&meta.user, max_user_length),
self.formatter.format_group(&meta.group, max_group_length),
@ -187,7 +187,7 @@ impl<'a> Core<'a> {
}
}
fn detect_user_lenght(&self, paths: &Vec<Meta>) -> usize {
fn detect_user_lenght(&self, paths: &[Meta]) -> usize {
let mut max: usize = 0;
for path in paths {
@ -199,7 +199,7 @@ impl<'a> Core<'a> {
max
}
fn detect_group_lenght(&self, paths: &Vec<Meta>) -> usize {
fn detect_group_lenght(&self, paths: &[Meta]) -> usize {
let mut max: usize = 0;
for path in paths {
@ -211,7 +211,7 @@ impl<'a> Core<'a> {
max
}
fn detect_size_lenghts(&self, paths: &Vec<Meta>) -> (usize, usize) {
fn detect_size_lenghts(&self, paths: &[Meta]) -> (usize, usize) {
let mut max_value_length: usize = 0;
let mut max_unit_size: usize = 0;

View file

@ -71,7 +71,7 @@ lazy_static! {
m.insert(Elem::FileLarge, Colour::RGB(0xFF, 0xB0, 0x00));
// Link
m.insert(Elem::Link, Colour::RGB(0x3B, 0xCE, 0xCe));
m.insert(Elem::Link, Colour::RGB(0x3B, 0xCE, 0xCE));
m
};
@ -87,15 +87,12 @@ impl Formatter {
pub fn format_name(&self, meta: &Meta) -> String {
let mut content = String::new();
let color = match meta.metadata.is_dir() {
true => {
content = content + "" + &meta.name;
Colors[&Elem::Dir]
}
false => {
content = content + &self.get_file_logo(&meta.path) + " " + &meta.name;
Colors[&Elem::UnrecognizedFile]
}
let color = if meta.metadata.is_dir() {
content = content + "" + &meta.name;
Colors[&Elem::Dir]
} else {
content = content + &self.get_file_logo(&meta.path) + " " + &meta.name;
Colors[&Elem::UnrecognizedFile]
};
content = color.paint(content).to_string();
@ -149,69 +146,69 @@ impl Formatter {
// User Read Permisssions
match mode & 0o400 {
0 => res = res + no_access.as_str(),
_ => res = res + read_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += read_perm.as_str(),
}
// User Write Permisssions
match mode & 0o200 {
0 => res = res + no_access.as_str(),
_ => res = res + write_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += write_perm.as_str(),
}
// User Exec Permisssions
match mode & 0o100 {
0 => res = res + no_access.as_str(),
_ => res = res + exec_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += exec_perm.as_str(),
}
// Group Read Permisssions
match mode & 0o040 {
0 => res = res + no_access.as_str(),
_ => res = res + read_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += read_perm.as_str(),
}
// Group Write Permisssions
match mode & 0o020 {
0 => res = res + no_access.as_str(),
_ => res = res + write_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += write_perm.as_str(),
}
// Group Exec Permisssions
match mode & 0o010 {
0 => res = res + no_access.as_str(),
_ => res = res + exec_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += exec_perm.as_str(),
}
// Other Read Permisssions
match mode & 0o040 {
0 => res = res + no_access.as_str(),
_ => res = res + read_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += read_perm.as_str(),
}
// Other Write Permisssions
match mode & 0o020 {
0 => res = res + no_access.as_str(),
_ => res = res + write_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += write_perm.as_str(),
}
// Other Exec Permisssions
match mode & 0o010 {
0 => res = res + no_access.as_str(),
_ => res = res + exec_perm.as_str(),
0 => res += no_access.as_str(),
_ => res += exec_perm.as_str(),
}
res.to_string()
}
pub fn format_user(&self, user_name: &String, max_user_size: usize) -> String {
pub fn format_user(&self, user_name: &str, max_user_size: usize) -> String {
if user_name.len() == max_user_size {
return Colors[&Elem::User].paint(user_name).to_string();
}
let mut content = String::with_capacity(max_user_size);
content = content + user_name;
content += user_name;
for _ in 0..(max_user_size - user_name.len()) {
content.push(' ');
@ -220,13 +217,13 @@ impl Formatter {
content
}
pub fn format_group(&self, group_name: &String, max_group_size: usize) -> String {
pub fn format_group(&self, group_name: &str, max_group_size: usize) -> String {
if group_name.len() == max_group_size {
return Colors[&Elem::Group].paint(group_name).to_string();
}
let mut content = String::with_capacity(max_group_size);
content = content + group_name;
content += group_name;
for _ in 0..(max_group_size - group_name.len()) {
content.push(' ');
@ -247,20 +244,20 @@ impl Formatter {
content.push(' ');
}
content = content + meta.size_value.as_str();
content += meta.size_value.as_str();
content.push(' ');
content = content + meta.size_unit.as_str();
content += meta.size_unit.as_str();
for _ in 0..(max_unit_size - meta.size_unit.len()) {
content.push(' ');
}
if meta.metadata.len() < 10 * 1044 * 1024 {
return Colors[&Elem::FileSmall].paint(content).to_string();
Colors[&Elem::FileSmall].paint(content).to_string()
} else if meta.metadata.len() < 100 * 1044 * 1024 {
return Colors[&Elem::FileMedium].paint(content).to_string();
Colors[&Elem::FileMedium].paint(content).to_string()
} else {
return Colors[&Elem::FileLarge].paint(content).to_string();
Colors[&Elem::FileLarge].paint(content).to_string()
}
}