Small Rust scripts

Merge pull request #3 from mbStavola/add-rustfmt-config

Reformat scripts

authored by

Matt Freitas-Stavola and committed by
GitHub
08b599c2 ca15b7d9

+54 -49
+9 -13
cidrcheck
··· 2 2 3 3 // cargo-deps: argh = "0.1", cidr = "0.2.1" 4 4 5 - use argh::FromArgs; 6 - use cidr::IpCidr; 7 - 8 5 use std::net::IpAddr; 9 6 use std::str::FromStr; 7 + 8 + use argh::FromArgs; 9 + use cidr::IpCidr; 10 10 11 11 #[derive(FromArgs)] 12 12 #[argh(description = "Display the ip range for a CIDR and check if an ip falls within.")] ··· 18 18 )] 19 19 ip: Option<IpAddr>, 20 20 21 - #[argh( 22 - positional, 23 - description = "CIDR to inspect", 24 - from_str_fn(parse_cidr) 25 - )] 21 + #[argh(positional, description = "CIDR to inspect", from_str_fn(parse_cidr))] 26 22 cidr: IpCidr, 27 23 } 28 24 29 25 fn main() { 30 26 let App { ip, cidr } = argh::from_env(); 31 27 println!( 32 - "CIDR {} has a range of: {} to {}", 33 - cidr, 34 - cidr.first_address(), 28 + "CIDR {} has a range of: {} to {}", 29 + cidr, 30 + cidr.first_address(), 35 31 cidr.last_address() 36 32 ); 37 33 38 34 println!("CIDR {} has a netmask of {}", cidr, cidr.mask()); 39 - 35 + 40 36 if let Some(ip) = ip { 41 37 print!("IP {}", ip); 42 38 let falls_within = cidr.contains(&ip); ··· 46 42 print!(" does not fall "); 47 43 } 48 44 49 - println!("within {}", cidr); 45 + println!("within {}", cidr); 50 46 } 51 47 } 52 48
+8 -9
dbg_server
··· 2 2 3 3 // cargo-deps: argh = "0.1" 4 4 5 - use argh::FromArgs; 6 - 5 + use std::io::{BufRead, BufReader}; 7 6 use std::net::TcpListener; 8 - use std::io::BufRead; 9 - use std::io::BufReader; 10 7 use std::str; 8 + 9 + use argh::FromArgs; 11 10 12 11 #[derive(FromArgs)] 13 12 #[argh(description = "simple debug server which logs the data sent to it.")] ··· 35 34 let stream = stream.expect("stream should be present"); 36 35 let mut stream = BufReader::new(stream); 37 36 38 - // This is not the "best" way to get the data sent over 39 - // but it sure is the easiest :^) 40 - let data = stream.fill_buf().expect("should have data"); 41 - let output = str::from_utf8(data).expect("should be able to parse data as text"); 42 - println!("{}", output); 37 + // This is not the "best" way to get the data sent over 38 + // but it sure is the easiest :^) 39 + let data = stream.fill_buf().expect("should have data"); 40 + let output = str::from_utf8(data).expect("should be able to parse data as text"); 41 + println!("{}", output); 43 42 } 44 43 }
+3 -3
emojidex
··· 9 9 //! image = "0.23.14" 10 10 //! ``` 11 11 12 + use std::io::{BufReader, Cursor}; 13 + use std::str::FromStr; 14 + 12 15 use argh::FromArgs; 13 16 use image::io::Reader; 14 17 use reqwest::blocking::Client; 15 18 use serde::Deserialize; 16 19 use viuer::Config; 17 - 18 - use std::io::{BufReader, Cursor}; 19 - use std::str::FromStr; 20 20 21 21 const BASE_API_URL: &str = "https://www.emojidex.com/api/v1"; 22 22 const BASE_CDN_URL: &str = "https://cdn.emojidex.com/emoji";
+15 -10
flush_cache
··· 2 2 3 3 // cargo-deps: argh = "0.1" 4 4 5 + use std::io::{BufRead, BufReader, Write}; 6 + use std::net::{Shutdown, TcpStream}; 7 + 5 8 use argh::FromArgs; 6 - 7 - use std::net::Shutdown; 8 - use std::net::TcpStream; 9 - use std::io::BufRead; 10 - use std::io::BufReader; 11 - use std::io::Write; 12 9 13 10 const FLUSH_COMMAND: &str = "FLUSHALL\r\n"; 14 11 ··· 32 29 let address = format!("{}:{}", app.host, app.port); 33 30 let mut stream = TcpStream::connect(address).expect("should be able to connect to redis"); 34 31 35 - stream.write(FLUSH_COMMAND.as_bytes()).expect("should be able to write flush command"); 36 - stream.flush().expect("should be able to send flush command"); 37 - stream.shutdown(Shutdown::Write).expect("should be able to shutdown writer"); 32 + stream 33 + .write(FLUSH_COMMAND.as_bytes()) 34 + .expect("should be able to write flush command"); 35 + stream 36 + .flush() 37 + .expect("should be able to send flush command"); 38 + stream 39 + .shutdown(Shutdown::Write) 40 + .expect("should be able to shutdown writer"); 38 41 39 42 let mut stream = BufReader::new(stream); 40 43 41 44 let mut output = String::new(); 42 - let _ = stream.read_line(&mut output).expect("should be able to read response"); 45 + let _ = stream 46 + .read_line(&mut output) 47 + .expect("should be able to read response"); 43 48 println!("{}", &output); 44 49 }
+4 -4
ghoshare
··· 6 6 //! reqwest = { version = "0.11.3", features = ["blocking"] } 7 7 //! ``` 8 8 9 - use argh::FromArgs; 10 - use reqwest::blocking::Client; 11 - use reqwest::redirect::Policy; 12 - 13 9 use std::fs::OpenOptions; 14 10 use std::io::{BufReader, Read}; 15 11 use std::path::PathBuf; 16 12 use std::str::FromStr; 13 + 14 + use argh::FromArgs; 15 + use reqwest::blocking::Client; 16 + use reqwest::redirect::Policy; 17 17 18 18 const BASE_URL: &str = "https://ghostbin.co"; 19 19
+2 -2
kill_port
··· 2 2 3 3 // cargo-deps: argh = "0.1" 4 4 5 - use argh::FromArgs; 6 - 7 5 use std::process::{self, Command}; 6 + 7 + use argh::FromArgs; 8 8 9 9 #[derive(FromArgs)] 10 10 #[argh(description = "Simple program to kill a process listening on a specific port.")]
+7
rustfmt.toml
··· 1 + version = "Two" 2 + edition = "2021" 3 + unstable_features = true 4 + imports_granularity = "Module" 5 + reorder_impl_items = true 6 + use_field_init_shorthand = true 7 + group_imports = "StdExternalCrate"
+2 -2
sierpinski
··· 2 2 3 3 // cargo-deps: argh = "0.1" 4 4 5 - use argh::FromArgs; 6 - 7 5 use std::fmt; 8 6 use std::str::FromStr; 7 + 8 + use argh::FromArgs; 9 9 10 10 const DELTA: &str = "Δ"; 11 11 const FILLED_TRIANGLE: &str = "▲";
+2 -2
stopwatch
··· 2 2 3 3 // cargo-deps: argh = "0.1", humantime = "2.1.0" 4 4 5 - use argh::FromArgs; 6 - 7 5 use std::thread; 8 6 use std::time::{Duration, Instant}; 7 + 8 + use argh::FromArgs; 9 9 10 10 #[derive(FromArgs)] 11 11 #[argh(description = "Keep track of how long a task runs or set a timer for some period of time.")]
+1 -2
strs
··· 2 2 3 3 // cargo-deps: argh = "0.1", object = "0.24.0" 4 4 5 - use argh::FromArgs; 6 - 7 5 use std::fs::OpenOptions; 8 6 use std::io::{self, BufReader, Read, Write}; 9 7 use std::path::PathBuf; 10 8 9 + use argh::FromArgs; 11 10 use object::{File, Object, ObjectSection, SectionKind}; 12 11 13 12 const MIN_STR_LEN: usize = 4;
+1 -2
tag_release
··· 19 19 fn main() { 20 20 let app: App = argh::from_env(); 21 21 22 - 23 - let tag = Utc::now().format(&app.format).to_string(); 22 + let tag = Utc::now().format(&app.format).to_string(); 24 23 25 24 println!("# Run the following to tag and release this version"); 26 25 println!();