A toolbox library that holds a useful collection of small unitilies written in Rust that make our life easier when writting Rust applications.
You can either use the utils-box crate and customize it by enabling/disabling features or if you are interested only on a single type of utils use one of the following specific crates directly:
- utils-box-archives
- utils-box-bits
- utils-box-config
- utils-box-connections
- utils-box-debug
- utils-box-logger
- utils-box-mathematics
- utils-box-pathfinder
- utils-box-stopwatch
- utils-box-linux
- utils-box-versions
A collection of useful methematic methods used in various DSP and other applications
Extract files from Tar, Gz and Zip Files
Mininal Example:
let archive: PathBuf = std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("test_archive.tar.gz");
let file: PathBuf = "treasure.hex".into();
let destination: PathBuf = std::env::current_exe()
.unwrap()
.parent()
.unwrap();
archives::extract_file(archive, ArchiveType::Gz, file, destination).unwrap();Convertions between different representations of raw bit streams
Mininal Example:
let received_bit_stream: u64 = 0b110101000100111010110;
let bytes = bits::bits_to_vec(received_bit_stream,21);
println!("Received bit stream: {} ", bits::bit_vec_to_hex_string(&bytes));Manipulate INI-style configuration files by checking for changes, updates etc
Mininal Example:
let mut config_changes = ini_compare(
&old_config_path.to_path_buf(),
&new_config_path.to_path_buf(),
)
.unwrap();
println!("{:#?}", config_changes);Initialize terminal and file loggers fast. Macros for log printing to either log or stdout (if a global logger is not initialized)
Mininal Example:
log_info!("INFO Test TO PRINTLN!");
log_debug!("DEBUG Test TO PRINTLN!");
terminal_logger_init(LevelFilter::Debug);
log_info!("INFO Test TO LOGGER!");
log_debug!("DEBUG Test TO LOGGER!");Search paths for a specific file in directories with known or unknown paths
Mininal Example:
let paths = IncludePathsBuilder::new()
.include_exe_dir()
.include_known("/home/user/")
.include_unknown("utils-box")
.build();
let pattern = "test_*.tar";
let file_found_in = paths.search_glob(pattern);Keep track of execution times in various points in binaries. Print records.
Minimal Example:
let mut s = TimeKeeper::init();
let mut t = TimeKeeper::init();
s.totals();
s.lap("init");
for _ in 0..5 {
std::thread::sleep(Duration::from_millis(5));
s.lap("loop");
t.lap("loop");
}
s.lap_totals("loop");
std::thread::sleep(Duration::from_millis(1234));
s.lap("after");
s.totals();
t.totals();
s.merge(t);
s.totals();version parser from strings using the semver.org notations
Mininal Example:
let version = "0.9.2-1e341234";
let mut expected = Version::new(0, 9, 2);
expected.pre = Prerelease::new("1e341234").unwrap();
assert_eq!(semver_parse(version).unwrap(), expected);Connect via SSH to a server to perform commands, upload & download files
Mininal Example:
let ssh = SshClient::local("user".to_string(), "1234".to_string()).unwrap();
let stdout = ssh.execute_cmd("ls").unwrap();
println!("{:?}", stdout);Connect via TCP to a socket to send and receive data
Mininal Example:
let mut tcp_client = TcpClient::new("192.168.1.17".to_string(), 36457)?;
let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
tcp_client.send(&data)?;
// Block and wait for response
let resp = tcp_client.receive()?;
println!("{:?}", resp);Connect via UDP to a socket to send and receive data
Mininal Example:
let mut udp =
UdpClient::new("0.0.0.0".to_string(), "192.168.1.31".to_string(), 6123).unwrap();
udp.send(b"\r").unwrap();
// Block and wait for response
let data = udp.receive().unwrap();
println!("{:?} => {}", data, String::from_utf8_lossy(&data));Connect to a ZMQ server to send and receive data
Mininal Example:
let zmq_client = ZmqClient::new(("192.168.1.17".to_string(), 36457)?;
let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
zmq_client.send(&data)?;
// Block and wait for response
let resp = zmq_client.receive()?;
println!("{:?}", resp);-
Make sure you have the following system-level dependencies installed:
sudo apt install pkg-config build-essential fontconfig libfontconfig1-dev -
Verify that
pkg-configcan detectlibstdc++properly:pkg-config --libs libstdc++ -
If
libstdc++is not detected, add the symbolic link:sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so /usr/lib/libstdc++.so