#file #size #humanize #bytes #sizes

humansize

A configurable crate to easily represent file sizes in a human-readable format

6 releases (stable)

1.1.0 Dec 23, 2017
1.0.2 Nov 22, 2017
1.0.1 Mar 15, 2017
1.0.0 Jan 17, 2017
0.1.1 Nov 19, 2016

#14 in Value formatting

Download history 3047/week @ 2019-01-20 2762/week @ 2019-01-27 2389/week @ 2019-02-03 2364/week @ 2019-02-10 2215/week @ 2019-02-17 2111/week @ 2019-02-24 2279/week @ 2019-03-03 2133/week @ 2019-03-10 1881/week @ 2019-03-17 2052/week @ 2019-03-24 2259/week @ 2019-03-31 2730/week @ 2019-04-07 2402/week @ 2019-04-14 2387/week @ 2019-04-21 2578/week @ 2019-04-28

2,343 downloads per month
Used in 78 crates (14 directly)

MIT/Apache

13KB
227 lines

Humansize travis badge

Documentation

Humansize lets you easily represent file sizes in a human-friendly format. You can specify your own formatting style or pick among the three defaults provided by the library:

  • Decimal (Multiples of 1000, KB units)
  • Binary (Multiples of 1024, KiB units)
  • Conventional (Multiples of 1024, KB units)

How to use it

Cargo.Toml:

[dependencies]
humansize = "1.0.1"

Simply import the FileSize trait and the options module and call the file_size method on any positive integer, using one of the three standards provided by the options module.

extern crate humansize;
use humansize::{FileSize, file_size_opts as options};

fn main() {
	let size = 1000;
	println!("Size is {}", size.file_size(options::DECIMAL).unwrap());

	println!("Size is {}", size.file_size(options::BINARY).unwrap());

	println!("Size is {}", size.file_size(options::CONVENTIONAL).unwrap());
}

If you wish to customize the way sizes are displayed, you may create your own custom FileSizeOpts struct and pass that to the method. See the custom_options.rs file in the example folder.

No runtime deps