|
1 | 1 | //! ByteSize is a utility that easily makes bytes size representation and helps |
2 | 2 | //! its arithmetic operations. |
3 | 3 | //! |
4 | | -//! ## Example |
| 4 | +//! ## Human Readable Representation |
5 | 5 | //! |
6 | | -//! ```ignore |
| 6 | +//! ByteSize provides a human readable string conversion as follows: |
| 7 | +//! |
| 8 | +//! ``` |
7 | 9 | //! extern crate bytesize; |
8 | 10 | //! |
9 | | -//! use bytesize::ByteSize; |
| 11 | +//! use bytesize::{ByteSize, IEC, SI}; |
10 | 12 | //! |
11 | | -//! fn byte_arithmetic_operator() { |
12 | | -//! let x = ByteSize::mb(1); |
13 | | -//! let y = ByteSize::kb(100); |
| 13 | +//! assert_eq!("482.4 GiB".to_string(), ByteSize::gb(518).humanize(IEC)); |
| 14 | +//! assert_eq!("518.0 GB".to_string(), ByteSize::gb(518).humanize(SI)); |
| 15 | +//! ``` |
14 | 16 | //! |
15 | | -//! let plus = x + y; |
16 | | -//! print!("{} bytes", plus.as_u64()); |
| 17 | +//! ## Arithmetic |
17 | 18 | //! |
18 | | -//! let minus = ByteSize::tb(100) - ByteSize::gb(4); |
19 | | -//! print!("{} bytes", minus.as_u64()); |
20 | | -//! } |
21 | 19 | //! ``` |
| 20 | +//! extern crate bytesize; |
| 21 | +//! |
| 22 | +//! use bytesize::ByteSize; |
| 23 | +//! |
| 24 | +//! let x = ByteSize::mb(1); |
| 25 | +//! let y = ByteSize::kb(100); |
22 | 26 | //! |
23 | | -//! It also provides its human readable string as follows: |
| 27 | +//! let sum = x + y; |
| 28 | +//! assert_eq!(sum, ByteSize::kb(1100)); |
24 | 29 | //! |
25 | | -//! ```ignore= |
26 | | -//! assert_eq!("482 GiB".to_string(), ByteSize::gb(518).to_string(true)); |
27 | | -//! assert_eq!("518 GB".to_string(), ByteSize::gb(518).to_string(false)); |
| 30 | +//! let product = 10u32 * x; |
| 31 | +//! assert_eq!(product, ByteSize::mb(10)); |
28 | 32 | //! ``` |
29 | 33 |
|
30 | 34 | #[cfg(feature = "serde")] |
|
0 commit comments