Skip to content

Commit 048cf54

Browse files
committed
Minor code changes to follow good practices
1 parent abc8d63 commit 048cf54

File tree

4 files changed

+32
-48
lines changed

4 files changed

+32
-48
lines changed

source_code/huginn/src/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
use std::collections::HashMap;
1818
// File lib
1919
use std::fs::{File,OpenOptions};
20-
use std::io::{self,prelude::*};
20+
use std::io::prelude::*;
2121
// Path lib
2222
use std::path::Path;
2323
// Process lib
24-
use std::process::{self,ChildStdout,ChildStderr,ExitStatus,Stdio};
24+
use std::process;
2525

2626
use libstream::{Colors,Stream};
2727
use libcommand;
@@ -58,9 +58,9 @@ fn main() {
5858
let hservices: HashMap<String,String> = fservices.readkey();
5959
println!("Starting services (/etc/huginn/services)");
6060
// Take name and set ID to zero
61-
let mut h_s_service: HashMap<String,i64> = {
61+
let h_s_service: HashMap<String,i64> = {
6262
let mut buff: HashMap<String,i64> = HashMap::new();
63-
for (serv,bin) in &hservices {
63+
for (serv,_bin) in &hservices {
6464
let serv = serv.trim().to_string();
6565
buff.insert(serv,0);
6666
}
@@ -80,7 +80,7 @@ fn main() {
8080
for handles in threads_services {
8181
match handles.join(){
8282
Ok(_d) => (),
83-
Err(e) => {
83+
Err(_e) => {
8484
eprintln!("{}[ERR]Failing awaiting for thread!{}", color.red, color.reset);
8585
()
8686
},

source_code/libcommand/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@
1414
1515

1616
// Process crate
17-
use std::process::{self,ChildStderr,ChildStdout,ExitStatus,Stdio};
17+
use std::process::{self,ExitStatus,Stdio};
1818
// HashMap
1919
use std::collections::HashMap;
20-
// IO lib
21-
use std::io::{self,prelude::*};
20+
2221
// Thread and Sync libs
23-
use std::sync::{Arc, Mutex};
2422
use std::thread::{self,JoinHandle};
25-
use std::sync::mpsc::channel;
2623

2724
// Colors
2825
use libstream::Colors;
2926

27+
3028
pub struct SService {
3129
id: i64,
3230
stdout: Vec<u8>,

source_code/rune/src/builtins.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use std::io::{self, Read, Write};
3030
use std::io::BufReader;
3131

3232
// thread lib
33-
use std::{thread, time};
33+
use std::thread;
3434

3535
// Unix lib
3636
use std::os::unix::fs::{symlink, MetadataExt, PermissionsExt};
3737

3838
// Process lib
39-
use std::process::{self, Command};
39+
use std::process::Command;
4040

4141
// Time lib
4242
use std::time::SystemTime;
@@ -170,12 +170,6 @@ fn info() -> String {
170170
String::from("File /proc/sys/kernel/random/boot_id doesn't exist.")
171171
};
172172

173-
// Read file and save it to buffer.
174-
let os_name = file_filter(&fileinfo, "NAME".to_string());
175-
let mut os_name = os_name[0].split('=');
176-
os_name.next();
177-
let os_name = os_name.next().unwrap();
178-
179173
let os_pretty = file_filter(&fileinfo, "PRETTY_NAME".to_string());
180174
let mut os_pretty = os_pretty[0].split('=');
181175
os_pretty.next();
@@ -275,7 +269,7 @@ fn base64(input: &String) -> Option<String> {
275269
for names in &input {
276270
let file = match fs::File::open(&names) {
277271
Ok(d) => d,
278-
Err(e) => return None,
272+
Err(_e) => return None,
279273
};
280274
if input.len() > 1 {
281275
strreturn = strreturn + &format!("filename {names} base64 {{ {} }}", file.encode_base64());
@@ -323,19 +317,19 @@ fn decodebase64(input: &String) -> Option<String> {
323317
None => return None,
324318
}) {
325319
Ok(d) => d,
326-
Err(e) => return None,
320+
Err(_e) => return None,
327321
};
328322

329323
let output = decode_base64(&buffer).expect("Error converting into binary");
330324

331325
match file.write_all(&output) {
332326
Ok(_d) => return Some( format!("{:?}: Saved correctly", input.get(1)) ),
333-
Err(e) => return None,
327+
Err(_e) => return None,
334328
}
335329
}
336330

337331
fn disk_usage(input: &String) -> Option<String> {
338-
let mut input = input.clone();
332+
let input = input.clone();
339333

340334
if input.split(' ').map(|e| e.to_string()).collect::<Vec<String>>().len() > 1 {
341335
return Some("Too many arguments. Pass just one path".to_string());
@@ -454,7 +448,7 @@ fn expand(input: String) -> String {
454448
}
455449

456450
fn count(input: &String) -> String {
457-
let mut output = String::new();
451+
let mut output;
458452
output = format!("Lines {{ {} }} \n",fs::read_to_string(input).expect("Error reading file.").lines().count());
459453

460454
output = output + &format!("Words - Letters {{ {:?} }} \n",fs::read_to_string(input).expect("Error reading file").word_count() );
@@ -699,7 +693,7 @@ fn ffalse(input: &String) -> Result<(),bool>{
699693
}
700694

701695
fn head(input: &String){
702-
let mut file;
696+
let file;
703697
let mut fdata = Default::default();
704698
let mut lnumber = 0;
705699
let mut cnumber = 1;
@@ -786,7 +780,7 @@ fn join(input: &String) -> Result<(),&str> {
786780
let lenght = files.len();
787781
let mut destination = match File::create(files[lenght-1]) {
788782
Ok(d) => d,
789-
Err(e) => {
783+
Err(_e) => {
790784
return Err("Error creating destination file");
791785
}
792786
};
@@ -796,7 +790,7 @@ fn join(input: &String) -> Result<(),&str> {
796790
for i in files {
797791
let file = match File::open(i.trim()){
798792
Ok(d) => d,
799-
Err(e) => {
793+
Err(_e) => {
800794
return Err("Error opening file");
801795
}
802796
};
@@ -806,8 +800,8 @@ fn join(input: &String) -> Result<(),&str> {
806800

807801
}
808802
match destination.write_all(fdata.as_bytes()){
809-
Ok(d) => return Ok(()),
810-
Err(e) => {
803+
Ok(_d) => return Ok(()),
804+
Err(_e) => {
811805
return Err("Error writting destination file from buffer");
812806
}
813807
};
@@ -825,7 +819,7 @@ fn ln(source: &Path, dest: &Path) -> Result<String,()>{
825819
fn ls(input: &String) -> String {
826820
// env::args() takes program's arguments
827821
// collect() takes arguments and returns in tuple
828-
let mut arguments: Vec<String> = input.split(' ').map(|e| e.to_string()).collect();
822+
let arguments: Vec<String> = input.split(' ').map(|e| e.to_string()).collect();
829823

830824
// Result buffer
831825
let mut buffer: Vec<String> = Vec::new();
@@ -1083,7 +1077,7 @@ fn number_line(input: &String) -> Result<(),&str>{
10831077
let mut fdata = String::new();
10841078
let file = match File::open( Path::new(input.trim()) ){
10851079
Ok(d) => d,
1086-
Err(e) => return Err("Error opening file, check permissions and file system"),
1080+
Err(_e) => return Err("Error opening file, check permissions and file system"),
10871081
};
10881082
let mut buff = BufReader::new(&file);
10891083
let _ = buff.read_to_string(&mut fdata);
@@ -1176,7 +1170,7 @@ fn remove_f_d(arguments: String) -> Result<(),String> {
11761170
}
11771171

11781172
fn show(input: &String) -> Option<String> {
1179-
let mut arguments: Vec<String> = input.trim().split(' ').map(|e| e.to_string()).collect();
1173+
let arguments: Vec<String> = input.trim().split(' ').map(|e| e.to_string()).collect();
11801174
let mut string_return = String::new();
11811175

11821176
// Init the configuration as clean
@@ -1225,7 +1219,7 @@ fn show(input: &String) -> Option<String> {
12251219
let buff = format!("stdin {{ {buffer} }}");
12261220
return Some(buff);
12271221
},
1228-
Err(j) => return None,
1222+
Err(_j) => return None,
12291223
}
12301224
return None;
12311225
}
@@ -1486,7 +1480,7 @@ pub fn rbuiltins(command: &str, b_arguments: String) -> Result<String,&str> {
14861480
} else if command == "nl" {
14871481
match number_line(&b_arguments){
14881482
Ok(()) => Ok("".to_string()),
1489-
Err(e) => Err("Error opening file, check permissions and file system"),
1483+
Err(_e) => Err("Error opening file, check permissions and file system"),
14901484
}
14911485
} else if command == "rm" {
14921486
match remove_f_d(b_arguments) {
@@ -1496,7 +1490,7 @@ pub fn rbuiltins(command: &str, b_arguments: String) -> Result<String,&str> {
14961490
} else if command == "proc" {
14971491
match proc() {
14981492
Ok(d) => Ok(d),
1499-
Err(e) => Err("Error getting processes"),
1493+
Err(_e) => Err("Error getting processes"),
15001494
}
15011495
} else if command == "pwd" {
15021496
match pwd(){
@@ -1539,12 +1533,12 @@ pub fn rbuiltins(command: &str, b_arguments: String) -> Result<String,&str> {
15391533
} else if command == "id" {
15401534
match id(&b_arguments) {
15411535
Ok(d) => Ok(d),
1542-
Err(e) => Err("Error getting environment variables"),
1536+
Err(_e) => Err("Error getting environment variables"),
15431537
}
15441538
} else if command == "join" {
15451539
match join(&b_arguments){
15461540
Ok(()) => Ok("Joined files".to_string()),
1547-
Err(e) => Err("Error joining files, verify arguments, permissions and/or space"),
1541+
Err(_e) => Err("Error joining files, verify arguments, permissions and/or space"),
15481542
}
15491543
} else if command == "list" || command == "help"{
15501544
result = format!(" Bultins, they are called with '_'; {{\n {:?}\n}}\n\n{HBUILTINS}", LBUILTINS);
@@ -1584,7 +1578,7 @@ pub fn rbuiltins(command: &str, b_arguments: String) -> Result<String,&str> {
15841578
} else if command == "which" {
15851579
match fwhich(&b_arguments) {
15861580
Ok(d) => Ok(d),
1587-
Err(e) => Err("Not found"),
1581+
Err(_e) => Err("Not found"),
15881582
}
15891583
} else if command == "clear" {
15901584
let _ = clear();

source_code/rune/src/main.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//!
1313
//! Copyright; Joaquin "ShyanJMC" Crespo - 2022-2023
1414
15-
// Core crate
16-
use core::str::from_utf8;
1715

1816
// Process crate
1917
use std::process;
@@ -23,14 +21,8 @@ use std::collections::HashMap;
2321
// I/O crate
2422
// Buffer reading crate
2523
use std::io::{self, Write};
26-
use std::io::Read;
27-
use std::io::BufReader;
2824

2925
use std::fs::OpenOptions;
30-
use std::fs::File;
31-
32-
// Path lib
33-
use std::path::Path;
3426

3527
// Import the files inside scope
3628
mod builtins;
@@ -342,7 +334,7 @@ fn main(){
342334

343335
let mut ffile = match OpenOptions::new().create(true).append(true).open(&second_part) {
344336
Ok(d) => d,
345-
Err(e) => {
337+
Err(_e) => {
346338
eprintln!("Error creating/opening file");
347339
continue;
348340
},
@@ -380,7 +372,7 @@ fn main(){
380372

381373
let mut efile = match OpenOptions::new().create(true).append(true).open(&second_part) {
382374
Ok(d) => d,
383-
Err(e) => {
375+
Err(_e) => {
384376
eprintln!("Error creating/opening file");
385377
continue;
386378
},
@@ -446,7 +438,7 @@ fn main(){
446438
proc2.stdin(Stdio::from(output1));
447439

448440
// Spawn execute it
449-
let mut nproc2 = match proc2.spawn(){
441+
let nproc2 = match proc2.spawn(){
450442
Ok(d) => d,
451443
Err(_e) => {
452444
eprintln!("Error executing command. Check if binary/command exists, you can try executing with absolute path.");

0 commit comments

Comments
 (0)