|
30 | 30 | //! [examples/rust_cookbook.rs](https://github.com/rust-shell-script/rust_cmd_lib/blob/master/examples/rust_cookbook.rs). |
31 | 31 | //! Since they are rust code, you can always rewrite them in rust natively in the future, if necessary without spawning external commands. |
32 | 32 | //! |
33 | | -//! ## What this library looks like |
34 | | -//! |
35 | | -//! To get a first impression, here is an example from |
36 | | -//! [examples/dd_test.rs](https://github.com/rust-shell-script/rust_cmd_lib/blob/master/examples/dd_test.rs): |
37 | | -//! |
38 | | -//! ```no_run |
39 | | -//! # use byte_unit::Byte; |
40 | | -//! # use cmd_lib::*; |
41 | | -//! # use rayon::prelude::*; |
42 | | -//! # use std::time::Instant; |
43 | | -//! # const DATA_SIZE: u64 = 10 * 1024 * 1024 * 1024; // 10GB data |
44 | | -//! # let mut file = String::new(); |
45 | | -//! # let mut block_size: u64 = 4096; |
46 | | -//! # let mut thread_num: u64 = 1; |
47 | | -//! run_cmd! ( |
48 | | -//! info "Dropping caches at first"; |
49 | | -//! sudo bash -c "echo 3 > /proc/sys/vm/drop_caches"; |
50 | | -//! info "Running with thread_num: $thread_num, block_size: $block_size"; |
51 | | -//! )?; |
52 | | -//! let cnt = DATA_SIZE / thread_num / block_size; |
53 | | -//! let now = Instant::now(); |
54 | | -//! (0..thread_num).into_par_iter().for_each(|i| { |
55 | | -//! let off = cnt * i; |
56 | | -//! let bandwidth = run_fun!( |
57 | | -//! sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1" |
58 | | -//! | awk r#"/copied/{print $(NF-1) " " $NF}"# |
59 | | -//! ) |
60 | | -//! .unwrap_or_else(|_| cmd_die!("thread $i failed")); |
61 | | -//! info!("thread {i} bandwidth: {bandwidth}"); |
62 | | -//! }); |
63 | | -//! let total_bandwidth = Byte::from_bytes((DATA_SIZE / now.elapsed().as_secs()) as u128).get_appropriate_unit(true); |
64 | | -//! info!("Total bandwidth: {total_bandwidth}/s"); |
65 | | -//! # Ok::<(), std::io::Error>(()) |
66 | | -//! ``` |
67 | | -//! |
68 | | -//! Output will be like this: |
69 | | -//! |
70 | | -//! ```console |
71 | | -//! ➜ rust_cmd_lib git:(master) ✗ cargo run --example dd_test -- -b 4096 -f /dev/nvme0n1 -t 4 |
72 | | -//! Finished dev [unoptimized + debuginfo] target(s) in 0.04s |
73 | | -//! Running `target/debug/examples/dd_test -b 4096 -f /dev/nvme0n1 -t 4` |
74 | | -//! [INFO ] Dropping caches at first |
75 | | -//! [INFO ] Running with thread_num: 4, block_size: 4096 |
76 | | -//! [INFO ] thread 3 bandwidth: 317 MB/s |
77 | | -//! [INFO ] thread 1 bandwidth: 289 MB/s |
78 | | -//! [INFO ] thread 0 bandwidth: 281 MB/s |
79 | | -//! [INFO ] thread 2 bandwidth: 279 MB/s |
80 | | -//! [INFO ] Total bandwidth: 1.11 GiB/s |
81 | | -//! ``` |
82 | | -//! |
83 | 33 | //! ## What this library provides |
84 | 34 | //! |
85 | 35 | //! ### Macros to run external commands |
|
324 | 274 | //! |
325 | 275 | //! ## Other Notes |
326 | 276 | //! |
| 277 | +//! ### Minimum supported Rust version |
| 278 | +//! |
| 279 | +//! cmd_lib(2.0)'s MSRV is 1.88. |
| 280 | +//! |
327 | 281 | //! ### Environment Variables |
328 | 282 | //! |
329 | 283 | //! You can use [std::env::var](https://doc.rust-lang.org/std/env/fn.var.html) to fetch the environment variable |
|
0 commit comments