Doe is a versatile Rust crate that significantly enhances the development workflow by offering an extensive collection of useful macros and utility functions. It streamlines common tasks and provides convenient features for clipboard management, state management, keyboard input, and mouse interaction. Additionally, doe includes robust cryptographic functions, enabling developers to easily integrate secure encryption, decryption, and hashing capabilities into their applications, ensuring data integrity and confidentiality.
Cryptographic Functions: AES, RSA, SHA, MD5 and Blake3 implementations
File System Utilities: Advanced file operations and management
Random Number Generation: LCG-based random number generator
System Utilities: Process management and system commands
Optional Features
To use specific features, add them to your Cargo.toml:
[dependencies]
doe = { version = "1.0", features = ["ctf", "clip", "mouse"] }
Available Features:
Feature
Description
Command
ctf
String manipulation and encoding utilities
cargo add doe -F ctf
clip
Clipboard management
cargo add doe -F clip
mouse
Mouse input simulation
cargo add doe -F mouse
keyboard
Keyboard input simulation
cargo add doe -F keyboard
kcm
Keyboard, clipboard, and mouse combined
cargo add doe -F kcm
xlsx
Excel file manipulation
cargo add doe -F xlsx
docx
Word document manipulation
cargo add doe -F docx
date
Date and time utilities
cargo add doe -F date
screenshot
Screenshot capture and processing
cargo add doe -F screenshot
images
Image manipulation
cargo add doe -F images
crypto
Cryptographic functions
cargo add doe -F crypto
asyncrs
Async runtime utilities
cargo add doe -F asyncrs
logger
Logging utilities
cargo add doe -F logger
sqlserver
SQL Server database operations
cargo add doe -F sqlserver
axumserver
Axum server utilities
cargo add doe -F axumserver
ip_addr
IP address utilities
cargo add doe -F ip_addr
http
HTTP client and server utilities
cargo add doe -F http
process
Process management utilities
cargo add doe -F process
json
JSON manipulation utilities
cargo add doe -F json
Modules
Core Modules
asyncrs: Async runtime utilities for concurrent programming
clipboard: Clipboard operations for copying and pasting data
color: Color format conversions between RGB and HEX
consts: Common constants used throughout the crate
crypto: Cryptographic functions including AES, RSA, SHA, MD5 and Blake3
ctf: String manipulation and encoding utilities
date: Date and time utilities
docx: Word document manipulation
fs: File system operations
httprs: HTTP request utilities
images: Image manipulation
ip_addr: IP address parsing and manipulation
json: JSON manipulation
keyboard: Keyboard input simulation
logger: Logging utilities
macros: Utility macros
mouse: Mouse input simulation
process: Process management
rand: Random number generation
screenshot: Screenshot utilities
axumserver: Axum server utilities
sqlserver: SQL Server database operations
structs: Custom data structures
timer: Timer utilities
traits: Shared behavior definitions
xlsx: Excel file manipulation
zoml: ZOML format utilities
Usage
Add doe to your Cargo.toml:
[dependencies]
doe = "1.0"
Examples
crypto example
let data = "this is data".as_bytes();
let enc_data = doe::crypto::aes::aes_ecb_encrypt("12345678123456781234567812345678".as_bytes(),"1234567812345678".as_bytes(),data).unwrap();
let dec_data = doe::crypto::aes::aes_ecb_decrypt("12345678123456781234567812345678".as_bytes(),"1234567812345678".as_bytes(),&enc_data).unwrap();
println!("data:{:?}",&data);
println!("enc_data:{:?}",&enc_data);
println!("dec_data:{:?}",&dec_data);
println!("blake3:{:?}",doe::crypto::blake3_xof("dnrops".as_bytes(), 10));
keyboard example
// cargo add doe -F kcm
use doe::keyboard::key_click;
use doe::keyboard::key_press;
use doe::keyboard::key_release;
use doe::keyboard::KeyCode;
use doe::mouse_drag;
use doe::move_to_paste;
use doe::move_to_press_left;
use doe::*;
use keyboard::exit_if_click_esc;
let list = vec!["iphone","ipad","macbook"];
// crete new baogao
move_to_press_left(857, 588).sleep(1.0); //#000000
// create fengmian
move_to_paste(1540, 853, "Apple").sleep(1.0); //#000000
move_to_paste(1360, 882, "ID").sleep(1.0); //#000000
// add shuoming
move_to_paste(772, 464, "Discription").sleep(1.0); //#ffffff
mouse_drag((894, 719).into(), (821, 716).into()).sleep(1.0); //#f0f0f0
key_click("2024-01-23").sleep(1.0);
move_to_press_left(740, 305).sleep(1.0); //#f0f0f0
for name in list {
// add baobao
move_to_press_left(476, 253).sleep(1.0); //#ffffff
// name
move_to_press_left(796, 331).sleep(1.0); //#ffffff
key_click("end");
key_click("shift+home");
set_clipboard(name).unwrap().sleep(0.5);
key_click("ctrl+v");
// add fujian
move_to_press_left(870, 587).sleep(1.0); //#000000
mouse_drag((893, 818).into(), (814, 816).into()).sleep(1.0); //#f0f0f0
key_click("2024-01-23").sleep(1.0);
move_to_press_left(723, 206).sleep(1.0); //#000000
}
// set taoshu
move_to_paste(1341, 910, "New_name").sleep(1.0); //#000000
docx_replace
//finds all 'name' and replace with 'andrew'
use doe::*;
docx::docx_replace("./name.docx","name","andrew").unwrap();
docx::docx_get_content("./name.docx").unwrap().dprintln();
docx::docx_remove_read_only("./name.docx").unwrap();
Spawn trait
use doe::*;
use doe::keyboard::exit_if_click_esc;
let t1 = run.spawn();
let t2 = exit_if_click_esc.spawn();
t1.join();
t2.join();
listen keybord and mouse
fn main() {
use doe::keyboard::listen_keybord;
use doe::listen_mouse_position;
use doe::listen_mouse_scroll;
use doe::listen_mouse_click;
let t1 = std::thread::spawn(||{
listen_keybord();
});
let t2 = std::thread::spawn(||{
listen_mouse_position();
});
let t3 = std::thread::spawn(||{
listen_mouse_scroll();
});
let t4 = std::thread::spawn(||{
listen_mouse_click();
});
t1.join().unwrap();
t2.join().unwrap();
t3.join().unwrap();
t4.join().unwrap();
}
use doe::automater;
let script = include_str!("../script.m");
automater(script);
mouse automater
fn main() {
use doe::mouse;
let script = r#"
move_to::217::135
sleep::1
move_to_press_left::189::137
sleep::1
move_to_press_left::198::185
sleep::1
move_drag::655::343::678::330
sleep::1
// script comment
move_to_paste::479::715::page demo is ok
"#
.trim();
mouse::mouse_automater(script);
}
mouse press left drag
fn main(){
use doe::mouse_drag;
mouse_press_left_drag((543,446).into(), (590,460).into());
mouse_drag((543,446).into(), (590,460).into(),"left");
}
fn main()->doe::DynError<()> {
use doe::get_clipboard;
use doe::set_clipboard;
set_clipboard("rust").unwrap();
let clip = get_clipboard().unwrap();
assert_eq!("rust",clip);
Ok(())
}
cargo add doe -F keyboard
keyboard example
fn main(){
use doe::keyboard::key_press;
use doe::keyboard::key_release;
use doe::keyboard::listen_mouse_position;
use doe::keyboard::get_mouse_position;
use doe::keyboard::listen_keybord;
use doe::keyboard::KeyCode;
key_press(KeyCode::COMMAND);
key_press(KeyCode::V);
key_release(KeyCode::V);
// listen key press and release
listen_keybord();
}
control mouse
cargo add doe -F mouse
#arch linux
sudo pacman -S xdotool
#Fedora OR Red Hat
sudo dnf install libxdo-devel
#Ubuntu OR Debian
sudo apt install libxdo-dev
#Cargo.toml add
[build]
rustflags = ["-L", "/usr/local/lib"]
#OR Cargo.toml add
[build]
rustflags = ["-l", "xdo"]
fn main()->doe::DynError<()> {
use std::time::Duration;
use doe::press;
move_to(300, 700);
press("left");
move_to_with_duration(0, 0,Duration::from_secs(5));
move_and_press_right(800,900);
press("right");
Ok(())
}
CopyString is a structure that implements the Copy trait
use doe::CopyString;
let mut s = CopyString::default();
s.push_str("11");
s.push_str("22");
s.push_str("33");
s.push_str("44");
dbg!(s);
s.println();
let a = s;
let b = a;
b.println();
implments Bts struct and bts! macro for Box<dyn Fn()> trait object
fn main() {
use doe::DebugPrint;
use doe::bfn;
use doe::Bfn;
#[derive(Debug)]
struct Demo<'a>{
name:&'a str
}
let f0 = bfn!(||{println!("ok");});
f0.call();
fn func()->Demo<'static>{
let d = Demo{name: "andrew"};
d
}
let f1 = bfn!(func);
f1.call().println();
fn sum()->usize{
9+89
}
let f2 = Bfn::new(Box::new(sum));//or bfn!(sum);
f2.call().println();
}
implments Bts struct and bts! macro for Box<dyn ToString> trait object
fn main() {
use doe::Print;
use doe::Str;
use doe::targets;
"this is a {s},I like Trait Object {p}%"
.format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100%
"this is a {d},I like Trait Object {p}}%"
.format(targets!{"{d}"=>"demo","{p}"=>100})
.println(); //this is a demo,I like Trait Object 100%
}
implment print println eprint eprintln for impl Display, impl Debug
use doe::Print;
use doe::DebugPrint;
"printable text".print();//impl Display
"printable text".println();
"printable text".eprintln();
#[derive(Debug)]
struct DebugPrintDemo{}//impl Debug
let d = DebugPrintDemo{};
d.dprint();
d.dprintln();
d.deprintln();
implment targets! for return Vec<(Box<dyn ToString>,Box<dyn ToString>)>
fn main() {
use doe::targets;
use doe::Print;
use doe::Str;
"this is a {d},I like Trait Object {p}}%"
.format(targets!{"{d}"=>"demo","{p}"=>100})
.println(); //this is a demo,I like Trait Object 100%
}
run timer by send stop_massge by channel
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
fn main() {
let (sender, receiver) = mpsc::channel::<bool>();
let t1 = thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
sender.send(true).unwrap();
});
let t2 = thread::spawn(move || {
run_timer_by_channel(Duration::from_secs(1), receiver, Box::new(|| {
println!("running..");
}));
});
t1.join().expect("Thread panicked");
t2.join().expect("Thread panicked");
}
run timer by shared state
fn main() {
use std::sync::{Arc, Mutex};
let run_state = Arc::new(Mutex::new(true));
let t1 = std::thread::spawn({
let run_state = Arc::clone(&run_state);
move || {
std::thread::sleep(std::time::Duration::from_secs(5));
*run_state.lock().unwrap() = false;
}
});
let t2 = std::thread::spawn({
let run_state = Arc::clone(&run_state);
move || {
run_timer_by_state(
std::time::Duration::from_secs(1),
run_state,
Box::new(|| {
// Function body goes here
println!("Running...");
}),
);
}
});
// Wait for the threads to finish
t1.join().expect("Thread panicked");
t2.join().expect("Thread panicked");
}
run timer anguments :start_time:Instant,step_time:Duration,stop_time:Duration,func:Box<dyn Fn()>
fn main() {
use doe::fs::*;
use doe::DebugPrint;
use doe::Str;
use std::ops::Deref;
use doe::fs::home_dir;
use doe::DebugPrint;
home_dir().display().dprintln();
// append data to file
append_data_to_file("demo.txt", "demo".as_bytes().to_vec()).unwrap();
// get all files and folders
walk_dir(".".to_path().deref()).unwrap().println();
// get all folders
walk_dir_get_files(".".to_path().deref()).unwrap().println();
// get all folders
walk_dir_get_folders(".".to_path().deref())
.unwrap()
.println();
//move file the directory to a new directory
move_file(
"/Users/ryanandrew/code/test/t1/demo.zip".to_path().deref(),
"/Users/ryanandrew/code/test/t2/d2.zip".to_path().deref(),
)
.unwrap();
//copy file the directory to a new directory
copy_file(
"/Users/ryanandrew/code/test/t1/demo.zip".to_path().deref(),
"/Users/ryanandrew/code/test/t2/d2.zip".to_path().deref(),
)
.unwrap();
//move all files in the directory to a new directory
move_folder(
"/Users/ryanandrew/code/test/t1".to_path().deref(),
"/Users/ryanandrew/code/test/t2/t1".to_path().deref(),
)
.unwrap();
//copy all files in the directory to a new directory
copy_folder(
"/Users/ryanandrew/code/test/d1".to_path().deref(),
"/Users/ryanandrew/code/test/d2".to_path().deref(),
)
.unwrap();
}
like pythons os.system() function
pub fn run() {
//linux and macos
system!("ping bing.com");
// in windows
system_powershell!("ls");
system!("python -m http.server"); //run in cmd
}
implment cut format for str and String
use doe::Str;
let a = "this is a demo {}";
let c = a.cut(-1,-2,1);
let f = a.format("so {}").format("how good is");
println!("{:?}",f);
println!("{:?}",c);
convert type
use doe::*;
let s = as_to!(5., i64);
assert_eq!(5, s);
if type is i8 return true
use doe::*;
assert_eq!(macros::is_i8(&5_i8),true);
if type is i16 return true
use doe::*;
assert_eq!(macros::is_i16(&5_i16),true);
if type is i32 return true
use doe::*;
assert_eq!(macros::is_i32(&5_i32),true);
if type is i64 return true
use doe::*;
assert_eq!(macros::is_i64(&5_i64),true);
if type is i128 return true
use doe::*;
assert_eq!(macros::is_i128(&5_i128),true);
if type is f32 return true
use doe::*;
assert_eq!(macros::is_f32(&5.0_f32),true);
if type is f64 return true
use doe::*;
assert_eq!(macros::is_f64(&5.0_f64),true);
returns a raised to the b power
use doe::*;
let p = powf!(2.,2.);
assert_eq!(p,4.0);
get argument and collect into Vec<String>
use doe::*;
//cargo run -- -n 100
let arg = args!();
assert_eq!(arg,vec![format!("-n"),format!("100")]);
get user input from terminal,return String
use doe::*;
let s = input!();
println!("{:?}",s);
Spliy &str by spliter and collect into Vec<String>
use doe::*;
let s = split_to_vec!("aa.bb",".");
assert_eq!(s,vec![format!("aa"),format!("bb")]);
read .csv file and Collect into Vec<Vec<String>>
use doe::*;
let s = read_csv!("./data.csv");
assert_eq!(s,vec![vec![format!("a"), format!("b"), format!("c")],vec![format!("1"), format!("2"), format!("3")],vec![format!("10"), format!("20"), format!("30")]]);
sorted new Vec
use doe::*;
let s1 = sorted!(vec![1.2, 2.6, 0.2]);
let s2 = sorted!(vec![8, 1_i128, 5_i128]);
assert_eq!(s1,vec![0.2,1.2,2.6]);
assert_eq!(s2,vec![1,5,8]);
sorted and deduped Vec
use doe::*;
let s1 = deduped_sorted!(vec![1.2, 1.2,2.6, 0.2]);
let s2 = deduped_sorted!(vec![8, 1_i128,8,5_i128]);
assert_eq!(s1,vec![0.2,1.2,2.6]);
assert_eq!(s2,vec![1,5,8]);
parse Vec element to type, parse Vec<&str> Collect to Vec<type>
use doe::*;
let v1: Vec<f64> = vec_element_parse!(vec!["15.", "2.9"], f64);
let v2: Vec<i128> = vec_element_parse!(vec!["15", "2"], i128);
let v3: Vec<f32> = vec_element_parse!(vec![".15", ".2"], f32);
assert_eq!(vec![15.0, 2.9], v1);
assert_eq!(vec![15, 2], v2);
assert_eq!(vec![0.15, 0.2], v3);
convert vec item to String,return Vec<String>
use doe::*;
let v1 = vec_element_to_string!(vec!["15.", "2.9"]);
let v2 = vec_element_to_string!(vec![15, 2]);
let v3 = vec_element_to_string!(vec![0.15, 0.2]);
assert_eq!(vec!["15.", "2.9"], v1);
assert_eq!(vec!["15", "2"], v2);
assert_eq!(vec!["0.15", "0.2"], v3);
return the array elements arranged from outermost elements to the middle element, traveling clockwise (n x n)
use doe::*;
let v1: Vec<f64> = vec_element_convert!(vec![1, 2], f64);
let v2: Vec<i32> = vec_element_convert!(vec![1.0, 2.0], i32);
let v3: Vec<i128> = vec_element_convert!(vec![1.0, 2.0], i128);
let v4: Vec<i32> = vec_element_convert!(vec![1_usize, 2_usize], i32);
let v5: Vec<i64> = vec_element_convert!(vec![0.15, 2.0], i64);
assert_eq!(v1, vec![1.0, 2.0]);
assert_eq!(v2, vec![1, 2]);
assert_eq!(v3, vec![1, 2]);
assert_eq!(v4, vec![1, 2]);
assert_eq!(v5, vec![0, 2]);
expr return max value
use doe::*;
let re_max = max!(1, 20);
assert_eq!(re_max,20);
expr return min value
use doe::*;
let re_min = min!(10, 2, 2, 5, 4, 6);
assert_eq!(re_min,2);
convert binary string to decimal
use doe::*;
let d1 = binary_to_decimal!("01101",i128);
assert_eq!(d1,13_i128);
let d2 = binary_to_decimal!("00000000000010100110001",i64);
assert_eq!(d2,1329_i64);
let d3 = binary_to_decimal!("000011",i32);
assert_eq!(d3,3_i32);
let d4 = binary_to_decimal!("000101",i16);
assert_eq!(d4,5_i16);
let d5 = binary_to_decimal!("001001",i8);
assert_eq!(d5,9_i8);
expr return memory address
use doe::*;
let d1 = binary_to_decimal!("01101",i128);
println!("{:?}",memory_address!(d1));//0x7ffcac734f08
use doe::*;
let v1 = vec_element_take!(vec![0, 1, 2],2);
assert_eq!(vec![0,1],v1);
zip two vec elements in tuple
use doe::*;
let v1 = vec_zip!(vec![0, 1, 2],vec![0, 1, 2]);
assert_eq!(vec![(0,0),(1,1),(2,2)],v1);
enumerate all indexs and elements collect tuple of vec
use doe::*;
let v1 = vec_enumerate!(vec![12, 11, 20]);
assert_eq!(vec![(0,12),(1,11),(2,20)],v1);
sort vec and return sorted vec
use doe::*;
let v1 = vec_sort!(vec![10, 2, 3]);
assert_eq!(vec![2,3,10],v1);
let v2 = vec_sort!(vec![1.8, 2.5, 0.3]);
assert_eq!(vec![0.3,1.8,2.5],v2);
has stable rust nightly return bool
use doe::*;
let v1 = has_nightly_compiler!();
assert_eq!(v1, true);
has stable rust compiler return bool
use doe::*;
let v1 = has_stable_compiler!();
assert_eq!(v1, false);
run command
use doe::*;
command!("ls -la");
command!("dust");
command!("lsd");
run a function once after a particularized delay(millis)
use doe::*;
set_timeout!(||{
println!("ok");
},3000);
run a function after a particularized delay(millis) each run delay(millis)
use doe::*;
duration_set_timeout!(||{
println!("ok");
},3000,1000); //from now delay 3000ms,each 1000ms run func()
run a function repeatedly, beginning after some millis, then repeating continuously at the given interval.
use doe::*;
set_interval!(||{
println!("ok");
},3000);
get current UTC-timestamp
use doe::*;
let t = utc_timestamp!();
eprintln!("{}", t);
get Local now
use doe::*;
let t = local_now!();
eprintln!("{}", t);
get Utc now
use doe::*;
let t = utc_now!();
eprintln!("{}", t);
macro for HashMap
use doe::*;
use std::collections::HashMap;
let mut map:HashMap<i32,i32> = hashmap!();
map.insert(0, 1);
let map1 = hashmap!(2=>5,3=>4);
macro for BTreeMap
use doe::*;
use std::collections::BTreeMap;
let mut map:BTreeMap<i32,i32> = btreemap!();
map.insert(0, 1);
let map1 = btreemap!(2=>5,3=>4);
License
This project is licensed under the MIT License - see the LICENSE file for details.
‘, ‘s’, ‘ ‘, ‘1’, ‘0’, ‘0’, ‘%’, ‘ ‘, ‘s’, ‘a’, ‘f’, ‘e’]
let b = Into::::into(“b”.to_string());
let b = Bts::from(“demo”);
}
## implmemt Debug,Display,Clone,Default,Drop trait for Struct
```rust
fn main() {
use std::sync::{Arc, Mutex};
use doe::*;
struct Doe{
pub name:String,
pub nickname: Box<str>,
key:Arc<Mutex<usize>>
}
impl_display!(Doe,name,nickname,key);
impl_debug!(Doe,name,nickname,key);
impl_default!(Doe,name,nickname,key);
impl_clone!(Doe,name,nickname,key);
impl_drop!(Doe,name,nickname,key);
let d = Doe{name:"andrew".to_string(), nickname: Box::from("func"),key:Arc::new(Mutex::new(15))};
let d1 = Doe::default();
println!("{:?}",d);
println!("{}",d1);
}
implment format for impl ToString
fn main() {
use doe::Print;
use doe::Str;
use doe::targets;
"this is a {s},I like Trait Object {p}%"
.format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100%
"this is a {d},I like Trait Object {p}}%"
.format(targets!{"{d}"=>"demo","{p}"=>100})
.println(); //this is a demo,I like Trait Object 100%
}
implment print println eprint eprintln for impl Display, impl Debug
use doe::Print;
use doe::DebugPrint;
"printable text".print();//impl Display
"printable text".println();
"printable text".eprintln();
#[derive(Debug)]
struct DebugPrintDemo{}//impl Debug
let d = DebugPrintDemo{};
d.dprint();
d.dprintln();
d.deprintln();
implment targets! for return Vec<(Box<dyn ToString>,Box<dyn ToString>)>
fn main() {
use doe::targets;
use doe::Print;
use doe::Str;
"this is a {d},I like Trait Object {p}}%"
.format(targets!{"{d}"=>"demo","{p}"=>100})
.println(); //this is a demo,I like Trait Object 100%
}
run timer by send stop_massge by channel
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
fn main() {
let (sender, receiver) = mpsc::channel::<bool>();
let t1 = thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
sender.send(true).unwrap();
});
let t2 = thread::spawn(move || {
run_timer_by_channel(Duration::from_secs(1), receiver, Box::new(|| {
println!("running..");
}));
});
t1.join().expect("Thread panicked");
t2.join().expect("Thread panicked");
}
run timer by shared state
fn main() {
use std::sync::{Arc, Mutex};
let run_state = Arc::new(Mutex::new(true));
let t1 = std::thread::spawn({
let run_state = Arc::clone(&run_state);
move || {
std::thread::sleep(std::time::Duration::from_secs(5));
*run_state.lock().unwrap() = false;
}
});
let t2 = std::thread::spawn({
let run_state = Arc::clone(&run_state);
move || {
run_timer_by_state(
std::time::Duration::from_secs(1),
run_state,
Box::new(|| {
// Function body goes here
println!("Running...");
}),
);
}
});
// Wait for the threads to finish
t1.join().expect("Thread panicked");
t2.join().expect("Thread panicked");
}
run timer anguments :start_time:Instant,step_time:Duration,stop_time:Duration,func:Box<dyn Fn()>
fn main() {
use doe::fs::*;
use doe::DebugPrint;
use doe::Str;
use std::ops::Deref;
use doe::fs::home_dir;
use doe::DebugPrint;
home_dir().display().dprintln();
// append data to file
append_data_to_file("demo.txt", "demo".as_bytes().to_vec()).unwrap();
// get all files and folders
walk_dir(".".to_path().deref()).unwrap().println();
// get all folders
walk_dir_get_files(".".to_path().deref()).unwrap().println();
// get all folders
walk_dir_get_folders(".".to_path().deref())
.unwrap()
.println();
//move file the directory to a new directory
move_file(
"/Users/ryanandrew/code/test/t1/demo.zip".to_path().deref(),
"/Users/ryanandrew/code/test/t2/d2.zip".to_path().deref(),
)
.unwrap();
//copy file the directory to a new directory
copy_file(
"/Users/ryanandrew/code/test/t1/demo.zip".to_path().deref(),
"/Users/ryanandrew/code/test/t2/d2.zip".to_path().deref(),
)
.unwrap();
//move all files in the directory to a new directory
move_folder(
"/Users/ryanandrew/code/test/t1".to_path().deref(),
"/Users/ryanandrew/code/test/t2/t1".to_path().deref(),
)
.unwrap();
//copy all files in the directory to a new directory
copy_folder(
"/Users/ryanandrew/code/test/d1".to_path().deref(),
"/Users/ryanandrew/code/test/d2".to_path().deref(),
)
.unwrap();
}
like pythons os.system() function
pub fn run() {
//linux and macos
system!("ping bing.com");
// in windows
system_powershell!("ls");
system!("python -m http.server"); //run in cmd
}
implment cut format for str and String
use doe::Str;
let a = "this is a demo {}";
let c = a.cut(-1,-2,1);
let f = a.format("so {}").format("how good is");
println!("{:?}",f);
println!("{:?}",c);
convert type
use doe::*;
let s = as_to!(5., i64);
assert_eq!(5, s);
if type is i8 return true
use doe::*;
assert_eq!(macros::is_i8(&5_i8),true);
if type is i16 return true
use doe::*;
assert_eq!(macros::is_i16(&5_i16),true);
if type is i32 return true
use doe::*;
assert_eq!(macros::is_i32(&5_i32),true);
if type is i64 return true
use doe::*;
assert_eq!(macros::is_i64(&5_i64),true);
if type is i128 return true
use doe::*;
assert_eq!(macros::is_i128(&5_i128),true);
if type is f32 return true
use doe::*;
assert_eq!(macros::is_f32(&5.0_f32),true);
if type is f64 return true
use doe::*;
assert_eq!(macros::is_f64(&5.0_f64),true);
returns a raised to the b power
use doe::*;
let p = powf!(2.,2.);
assert_eq!(p,4.0);
get argument and collect into Vec<String>
use doe::*;
//cargo run -- -n 100
let arg = args!();
assert_eq!(arg,vec![format!("-n"),format!("100")]);
get user input from terminal,return String
use doe::*;
let s = input!();
println!("{:?}",s);
Spliy &str by spliter and collect into Vec<String>
use doe::*;
let s = split_to_vec!("aa.bb",".");
assert_eq!(s,vec![format!("aa"),format!("bb")]);
read .csv file and Collect into Vec<Vec<String>>
use doe::*;
let s = read_csv!("./data.csv");
assert_eq!(s,vec![vec![format!("a"), format!("b"), format!("c")],vec![format!("1"), format!("2"), format!("3")],vec![format!("10"), format!("20"), format!("30")]]);
sorted new Vec
use doe::*;
let s1 = sorted!(vec![1.2, 2.6, 0.2]);
let s2 = sorted!(vec![8, 1_i128, 5_i128]);
assert_eq!(s1,vec![0.2,1.2,2.6]);
assert_eq!(s2,vec![1,5,8]);
sorted and deduped Vec
use doe::*;
let s1 = deduped_sorted!(vec![1.2, 1.2,2.6, 0.2]);
let s2 = deduped_sorted!(vec![8, 1_i128,8,5_i128]);
assert_eq!(s1,vec![0.2,1.2,2.6]);
assert_eq!(s2,vec![1,5,8]);
parse Vec element to type, parse Vec<&str> Collect to Vec<type>
use doe::*;
let v1: Vec<f64> = vec_element_parse!(vec!["15.", "2.9"], f64);
let v2: Vec<i128> = vec_element_parse!(vec!["15", "2"], i128);
let v3: Vec<f32> = vec_element_parse!(vec![".15", ".2"], f32);
assert_eq!(vec![15.0, 2.9], v1);
assert_eq!(vec![15, 2], v2);
assert_eq!(vec![0.15, 0.2], v3);
convert vec item to String,return Vec<String>
use doe::*;
let v1 = vec_element_to_string!(vec!["15.", "2.9"]);
let v2 = vec_element_to_string!(vec![15, 2]);
let v3 = vec_element_to_string!(vec![0.15, 0.2]);
assert_eq!(vec!["15.", "2.9"], v1);
assert_eq!(vec!["15", "2"], v2);
assert_eq!(vec!["0.15", "0.2"], v3);
return the array elements arranged from outermost elements to the middle element, traveling clockwise (n x n)
use doe::*;
let v1: Vec<f64> = vec_element_convert!(vec![1, 2], f64);
let v2: Vec<i32> = vec_element_convert!(vec![1.0, 2.0], i32);
let v3: Vec<i128> = vec_element_convert!(vec![1.0, 2.0], i128);
let v4: Vec<i32> = vec_element_convert!(vec![1_usize, 2_usize], i32);
let v5: Vec<i64> = vec_element_convert!(vec![0.15, 2.0], i64);
assert_eq!(v1, vec![1.0, 2.0]);
assert_eq!(v2, vec![1, 2]);
assert_eq!(v3, vec![1, 2]);
assert_eq!(v4, vec![1, 2]);
assert_eq!(v5, vec![0, 2]);
expr return max value
use doe::*;
let re_max = max!(1, 20);
assert_eq!(re_max,20);
expr return min value
use doe::*;
let re_min = min!(10, 2, 2, 5, 4, 6);
assert_eq!(re_min,2);
convert binary string to decimal
use doe::*;
let d1 = binary_to_decimal!("01101",i128);
assert_eq!(d1,13_i128);
let d2 = binary_to_decimal!("00000000000010100110001",i64);
assert_eq!(d2,1329_i64);
let d3 = binary_to_decimal!("000011",i32);
assert_eq!(d3,3_i32);
let d4 = binary_to_decimal!("000101",i16);
assert_eq!(d4,5_i16);
let d5 = binary_to_decimal!("001001",i8);
assert_eq!(d5,9_i8);
expr return memory address
use doe::*;
let d1 = binary_to_decimal!("01101",i128);
println!("{:?}",memory_address!(d1));//0x7ffcac734f08
Doe - A Versatile Rust Utility Crate
Doe is a versatile Rust crate that significantly enhances the development workflow by offering an extensive collection of useful macros and utility functions. It streamlines common tasks and provides convenient features for clipboard management, state management, keyboard input, and mouse interaction. Additionally, doe includes robust cryptographic functions, enabling developers to easily integrate secure encryption, decryption, and hashing capabilities into their applications, ensuring data integrity and confidentiality.
Features
Core Features
Optional Features
To use specific features, add them to your Cargo.toml:
Available Features:
cargo add doe -F ctf
cargo add doe -F clip
cargo add doe -F mouse
cargo add doe -F keyboard
cargo add doe -F kcm
cargo add doe -F xlsx
cargo add doe -F docx
cargo add doe -F date
cargo add doe -F screenshot
cargo add doe -F images
cargo add doe -F crypto
cargo add doe -F asyncrs
cargo add doe -F logger
cargo add doe -F sqlserver
cargo add doe -F axumserver
cargo add doe -F ip_addr
cargo add doe -F http
cargo add doe -F process
cargo add doe -F json
Modules
Core Modules
Usage
Add doe to your Cargo.toml:
Examples
crypto example
keyboard example
docx_replace
Spawn trait
listen keybord and mouse
automater
generate script
run to generate script
cargo r > script.m
script.m
run script
mouse automater
mouse press left drag
keyboard example
control mouse
CopyString is a structure that implements the Copy trait
implments Bts struct and bts! macro for Box<dyn Fn()> trait object
implments Bts struct and bts! macro for Box<dyn ToString> trait object
implment format for impl ToString
implment print println eprint eprintln for impl Display, impl Debug
implment targets! for return Vec<(Box<dyn ToString>,Box<dyn ToString>)>
run timer by send stop_massge by channel
run timer by shared state
run timer anguments :start_time:Instant,step_time:Duration,stop_time:Duration,func:Box<dyn Fn()>
useage of fs module
like pythons os.system() function
implment cut format for str and String
convert type
if type is i8 return true
if type is i16 return true
if type is i32 return true
if type is i64 return true
if type is i128 return true
if type is f32 return true
if type is f64 return true
returns a raised to the b power
get argument and collect into Vec<String>
get user input from terminal,return String
Spliy &str by spliter and collect into Vec<String>
read .csv file and Collect into Vec<Vec<String>>
sorted new Vec
sorted and deduped Vec
parse Vec element to type, parse Vec<&str> Collect to Vec<type>
convert vec item to String,return Vec<String>
return the array elements arranged from outermost elements to the middle element, traveling clockwise (n x n)
mutiply two matrix
find the fist element and remove
find element position and collect into Vec
slice vec by range
clone element by index
remove file or folder
get vec type ,return string type value
convert vec elements type
expr return max value
expr return min value
convert binary string to decimal
expr return memory address
Merge two Vec return merged Vec
take size of elements and return a new vec
zip two vec elements in tuple
enumerate all indexs and elements collect tuple of vec
sort vec and return sorted vec
has stable rust nightly return bool
has stable rust compiler return bool
run command
run a function once after a particularized delay(millis)
run a function after a particularized delay(millis) each run delay(millis)
run a function repeatedly, beginning after some millis, then repeating continuously at the given interval.
get current UTC-timestamp
get Local now
get Utc now
macro for HashMap
macro for BTreeMap
License
This project is licensed under the MIT License - see the LICENSE file for details. ‘, ‘s’, ‘ ‘, ‘1’, ‘0’, ‘0’, ‘%’, ‘ ‘, ‘s’, ‘a’, ‘f’, ‘e’] let b = Into::::into(“b”.to_string());
let b = Bts::from(“demo”);
}
implment format for impl ToString
implment print println eprint eprintln for impl Display, impl Debug
implment targets! for return Vec<(Box<dyn ToString>,Box<dyn ToString>)>
run timer by send stop_massge by channel
run timer by shared state
run timer anguments :start_time:Instant,step_time:Duration,stop_time:Duration,func:Box<dyn Fn()>
useage of fs module
like pythons os.system() function
implment cut format for str and String
convert type
if type is i8 return true
if type is i16 return true
if type is i32 return true
if type is i64 return true
if type is i128 return true
if type is f32 return true
if type is f64 return true
returns a raised to the b power
get argument and collect into Vec<String>
get user input from terminal,return String
Spliy &str by spliter and collect into Vec<String>
read .csv file and Collect into Vec<Vec<String>>
sorted new Vec
sorted and deduped Vec
parse Vec element to type, parse Vec<&str> Collect to Vec<type>
convert vec item to String,return Vec<String>
return the array elements arranged from outermost elements to the middle element, traveling clockwise (n x n)
mutiply two matrix
find the fist element and remove
find element position and collect into Vec
slice vec by range
clone element by index
remove file or folder
get vec type ,return string type value
convert vec elements type
expr return max value
expr return min value
convert binary string to decimal
expr return memory address
Merge two Vec return merged Vec
take size of elements and return a new vec
zip two vec elements in tuple
enumerate all indexs and elements collect tuple of vec
sort vec and return sorted vec
has stable rust nightly return bool
has stable rust compiler return bool
run command
run a function once after a particularized delay(millis)
run a function after a particularized delay(millis) each run delay(millis)
run a function repeatedly, beginning after some millis, then repeating continuously at the given interval.
get current UTC-timestamp
get Local now
get Utc now
macro for HashMap
macro for BTreeMap
License
This project is licensed under the MIT License - see the LICENSE file for details.