Crates.io | e-utils |
lib.rs | e-utils |
version | 0.4.6 |
source | src |
created_at | 2022-08-10 10:58:25.611387 |
updated_at | 2024-12-11 06:53:37.684871 |
description | a rust utils |
homepage | https://gitee.com/eternalnight996 |
repository | https://gitee.com/eternalnight996/e-utils |
max_upload_size | |
id | 642559 |
size | 395,280 |
This is a universal feature library that integrates convenient features
APP |
Windows 10 |
Unix |
Macos |
Description |
---|---|---|---|---|
fs_ext | โ |
x |
x |
[lock_share, lock_access, custom_flags2, attributes2, security_qos_flags2] |
Dialog | โ |
โ |
โ |
Cross-platform dialog functionality |
Base64 | โ |
โ |
โ |
Base64 encoding and decoding |
Algorithm | โ |
โ |
โ |
Random number generation, nanoid, and other algorithms |
Image | โ |
โ |
โ |
Image processing functionality |
cmd | โ |
โ |
โ |
Command line operations and management |
encode | โ |
โ |
โ |
Encoding conversion and automatic decoding |
http | โ |
โ |
โ |
HTTP request functionality |
regex | โ |
โ |
โ |
Regular expression support |
_ | ร |
ร |
ร |
Unimplemented or reserved functionality |
[dependencies]
e-utils = {version="0.4", feature=["algorithm","cmd","dialog"]}
fn main() {
e_utils::dialog::sync::warn("Title", "test");
e_utils::dialog::sync::folders();
e_utils::dialog::sync::files();
}
use e_utils::algorithm;
fn main() {
// ็ๆ้ๆบๅธๅฐๅผ
let random_bool = algorithm!();
println!("้ๆบๅธๅฐๅผ: {}", random_bool);
// ็ๆ้ๆบ u32
let random_u32: u32 = algorithm!(#u32);
println!("้ๆบ u32: {}", random_u32);
// ็ๆ้ๆบๆฐ็ป
let random_array: [u8; 5] = algorithm!([u8; 5]);
println!("้ๆบๆฐ็ป: {:?}", random_array);
// ็ๆ้ๆบ RGB ้ข่ฒ
let rgb = algorithm!(rgb 0, 255);
println!("้ๆบ RGB: {:?}", rgb);
// ็ๆ้ป่ฎค้ฟๅบฆ๏ผ21๏ผ็ nanoid
let default_nanoid = algorithm!(nanoid);
println!("้ป่ฎค nanoid: {}", default_nanoid);
// ็ๆ่ชๅฎไน้ฟๅบฆ็ nanoid
let custom_nanoid = algorithm!(nanoid 10);
println!("่ชๅฎไน nanoid: {}", custom_nanoid);
// ็ๆๆๅฎ่ๅดๅ
็้ๆบๆฐ
let random_range = algorithm!(0..100);
println!("้ๆบๆฐ (0-99): {}", random_range);
// ็ๆ่ดๆฐ่ๅดๅ
็้ๆบๆฐ
let negative_range = algorithm!((-50)..50);
println!("้ๆบๆฐ (-50 ๅฐ 49): {}", negative_range);
// ็ๆ่ชๅฎไนๅญๆฏ่กจ็ nanoid
let custom_alphabet_nanoid = algorithm!(nanoid 8, &"abcdef123456".chars().collect::<Vec<char>>());
println!("่ชๅฎไนๅญๆฏ่กจ nanoid: {}", custom_alphabet_nanoid);
// ไฝฟ็จไธๅฎๅ
จๆจกๅผ็ๆ nanoid
let unsafe_nanoid = algorithm!(nanoid unsafe 15);
println!("ไธๅฎๅ
จๆจกๅผ nanoid: {}", unsafe_nanoid);
// ไฝฟ็จไธๅฎๅ
จๆจกๅผๅ่ชๅฎไนๅญๆฏ่กจ็ๆ nanoid
let unsafe_custom_nanoid = algorithm!(nanoid unsafe 12, &"ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect::<Vec<char>>());
println!("ไธๅฎๅ
จๆจกๅผ่ชๅฎไนๅญๆฏ่กจ nanoid: {}", unsafe_custom_nanoid);
}
use e_utils::system::encode::auto_decode;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let bytes = vec![0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD]; // "ไฝ ๅฅฝ" in UTF-8
let decoded = auto_decode(&bytes)?;
assert_eq!(decoded, "ไฝ ๅฅฝ");
Ok(())
}
use e_utils::{shell_open, Cmd};
fn test_cmd() {
let output = Cmd::new("echo Hello from cmd").output().unwrap();
assert_eq!(output.stdout, "Hello from cmd");
assert!(Cmd::new("echo Hello from cmd")
.output()
.is_err());
}
fn test_shell_open_windows() {
assert!(shell_open("C:\\").is_ok());
}
fn main() {
test_cmd();
test_shell_open_windows();
}
use e_utils::{a_shell_open, Cmd};
async fn test_cmd() {
let output = Cmd::new("echo Hello from cmd").a_output().await.unwrap();
assert_eq!(output.stdout, "Hello from cmd");
assert!(Cmd::new("echo Hello from cmd")
.output()
.is_err());
}
async fn test_shell_open_windows() {
assert!(a_shell_open("C:\\").await.is_ok());
}
#[tokio::main]
async fn main() {
test_cmd().await;
test_shell_open_windows().await;
}
use std::time::Duration;
use e_utils::{tasks::sync::CmdManage, Cmd};
fn test_performance() {
use std::time::Instant;
let cmd_manage = CmdManage::new(8);
for _ in 0..1000 {
cmd_manage
.add_cmd(Cmd::new("echo").arg("Performance test"))
.unwrap();
}
let start = Instant::now();
cmd_manage.run().unwrap();
let duration = start.elapsed();
println!("Time taken to run 1000 commands: {:?}", duration);
assert!(
duration < Duration::from_secs(10),
"Performance test took too long"
);
}
fn main() {
test_performance();
}
๐ก!important๏ผ
# Donwloading the object
git clone https://github.com/eternalnight996/e-utils
cd e-utils
# test all object support
cargo test
# The benchmark results will help you understand the performance characteristics of e-utils in different scenarios.
cargo bench
Rand is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT, and COPYRIGHT for details.