utils_box/
lib.rs

1//! # Summary
2//! A toolbox library that holds a useful collection of small unitilies written in Rust that make our life easier when writting Rust applications.
3//!
4//! # Utilities provided:
5//!
6//! ## Mathematics
7//! A collection of useful methematic methods used in various DSP and other applications
8//!
9//! ## Archives
10//! Extract files from Tar, Gz and Zip Files
11//!
12//! Mininal Example:
13//! ```ignore
14//! let archive: PathBuf = std::env::current_exe()
15//!     .unwrap()
16//!     .parent()
17//!     .unwrap()
18//!     .join("test_archive.tar.gz");
19//!
20//! let file: PathBuf = "treasure.hex".into();
21//!
22//! let destination: PathBuf = std::env::current_exe()
23//!     .unwrap()
24//!     .parent()
25//!     .unwrap();
26//!
27//! archives::extract_file(archive, ArchiveType::Gz, file, destination).unwrap();
28//!
29//! ```
30//!
31//! ## Bits
32//! Convertions between different representations of raw bit streams
33//!
34//! Mininal Example:
35//! ```ignore
36//! let received_bit_stream: u64 = 0b110101000100111010110;
37//!
38//! let bytes = bits::bits_to_vec(received_bit_stream,21);
39//!
40//! println!("Received bit stream: {} ", bits::bit_vec_to_hex_string(&bytes));
41//!
42//! ```
43//!
44//! ## Config
45//! Manipulate INI-style configuration files by checking for changes, updates etc
46//!
47//! Mininal Example:
48//! ```ignore
49//!     let mut config_changes = ini_compare(
50//!         &old_config_path.to_path_buf(),
51//!         &new_config_path.to_path_buf(),
52//!     )
53//!     .unwrap();
54//!
55//!    println!("{:#?}", config_changes);
56//!
57//! ```
58//!
59//! ## Logger
60//! Initialize terminal and file loggers fast. Macros for log printing to either log or stdout (if a global logger is not initialized)
61//!
62//! Mininal Example:
63//! ```ignore
64//!     log_info!("INFO Test TO PRINTLN!");
65//!     log_debug!("DEBUG Test TO PRINTLN!");
66//!
67//!     terminal_logger_init(LevelFilter::Debug);
68//!
69//!     log_info!("INFO Test TO LOGGER!");
70//!     log_debug!("DEBUG Test TO LOGGER!");
71//!
72//! ```
73//!
74//! ## Paths
75//! Search paths for a specific file in directories with known or unknown paths
76//!
77//! Mininal Example:
78//! ```ignore
79//!     let paths = IncludePathsBuilder::new()
80//!             .include_exe_dir()
81//!             .include_known("/home/user/")
82//!             .include_unknown("utils-box")
83//!             .build();
84//!
85//!     let pattern = "test_*.tar";
86//!
87//!     let file_found_in = paths.search_glob(pattern);
88//!
89//! ```
90//!
91//! ## Stopwatch and Timekeper
92//! Keep track of execution times in various points in binaries. Print records.
93//!
94//! Minimal Example:
95//! ```ignore
96//!    let mut s = TimeKeeper::init();
97//!    let mut t = TimeKeeper::init();
98//!
99//!    s.totals();
100//!
101//!    s.lap("init");
102//!
103//!    for _ in 0..5 {
104//!        std::thread::sleep(Duration::from_millis(5));
105//!        s.lap("loop");
106//!        t.lap("loop");
107//!    }
108//!    s.lap_totals("loop");
109//!    std::thread::sleep(Duration::from_millis(1234));
110//!    s.lap("after");
111//!
112//!    s.totals();
113//!    t.totals();
114//!
115//!    s.merge(t);
116//!
117//!    s.totals();
118//!
119//! ```
120//!
121//! ## Versions
122//! version parser from strings using the `semver.org` notations
123//!
124//! Mininal Example:
125//! ```ignore
126//!    let version = "0.9.2-1e341234";
127//!
128//!     let mut expected = Version::new(0, 9, 2);
129//!     expected.pre = Prerelease::new("1e341234").unwrap();
130//!
131//!     assert_eq!(semver_parse(version).unwrap(), expected);
132//!
133//! ```
134//!
135//! ## SSH Client
136//! Connect via SSH to a server to perform commands, upload & download files
137//!
138//! Mininal Example:
139//! ```ignore
140//!     let ssh = SshClient::local("user".to_string(), "1234".to_string()).unwrap();
141//!
142//!     let stdout = ssh.execute_cmd("ls").unwrap();
143//!
144//!     println!("{:?}", stdout);
145//!
146//! ```
147//!
148//! ## TCP Client
149//! Connect via TCP to a socket to send and receive data
150//!
151//! Mininal Example:
152//! ```ignore
153//!     let mut tcp_client = TcpClient::new("192.168.1.17".to_string(), 36457)?;
154//!
155//!     let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
156//!
157//!     tcp_client.send(&data)?;
158//!
159//!     // Block and wait for response
160//!     let resp = tcp_client.receive()?;
161//!
162//!      println!("{:?}", resp);
163//!
164//! ```
165//!
166//! ## TCP Client
167//! Connect via UDP to a socket to send and receive data
168//!
169//! Mininal Example:
170//! ```ignore
171//!      let mut udp =
172//!             UdpClient::new("0.0.0.0".to_string(), "192.168.1.31".to_string(), 6123).unwrap();
173//!
174//!     udp.send(b"\r").unwrap();
175//!
176//!     // Block and wait for response
177//!     let data = udp.receive().unwrap();
178//!
179//!     println!("{:?} => {}", data, String::from_utf8_lossy(&data));
180//!
181//! ```
182//!
183//! ## ZMQ Client
184//! Connect to a ZMQ server to send and receive data
185//!
186//! Mininal Example:
187//! ```ignore
188//!     let zmq_client = ZmqClient::new(("192.168.1.17".to_string(), 36457)?;
189//!
190//!     let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
191//!
192//!     zmq_client.send(&data)?;
193//!
194//!     // Block and wait for response
195//!     let resp = zmq_client.receive()?;
196//!
197//!     println!("{:?}", resp);
198//!
199//! ```
200//!
201
202pub mod archives;
203pub mod bits;
204pub mod config;
205#[cfg(not(tarpaulin_include))]
206pub mod debug;
207pub mod paths;
208pub mod versions;
209
210#[cfg(not(tarpaulin_include))]
211#[cfg(target_family = "unix")]
212pub mod connections;
213
214#[macro_use]
215pub mod logger;
216pub mod stopwatch;
217
218#[cfg(target_family = "unix")]
219#[cfg(not(tarpaulin_include))]
220pub mod threads;
221
222pub mod mathematics;