summaryrefslogtreecommitdiffstats
path: root/vendor/humansize/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/humansize/examples
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/humansize/examples')
-rw-r--r--vendor/humansize/examples/custom_options.rs10
-rw-r--r--vendor/humansize/examples/sizes.rs16
2 files changed, 26 insertions, 0 deletions
diff --git a/vendor/humansize/examples/custom_options.rs b/vendor/humansize/examples/custom_options.rs
new file mode 100644
index 000000000..dbfd72f87
--- /dev/null
+++ b/vendor/humansize/examples/custom_options.rs
@@ -0,0 +1,10 @@
+extern crate humansize;
+use humansize::{format_size, FormatSizeOptions, DECIMAL};
+
+fn main() {
+ // Create a new FormatSizeOptions struct starting from one of the defaults
+ let custom_options = FormatSizeOptions::from(DECIMAL).decimal_places(5);
+
+ // Then use it
+ println!("{}", format_size(3024usize, custom_options));
+}
diff --git a/vendor/humansize/examples/sizes.rs b/vendor/humansize/examples/sizes.rs
new file mode 100644
index 000000000..72ba76616
--- /dev/null
+++ b/vendor/humansize/examples/sizes.rs
@@ -0,0 +1,16 @@
+extern crate humansize;
+
+use humansize::{format_size, format_size_i, SizeFormatter, ISizeFormatter, BINARY, DECIMAL, WINDOWS};
+
+fn main() {
+ println!("{}", format_size(5456usize, BINARY));
+ println!("{}", format_size(1024usize, DECIMAL));
+ println!("{}", format_size(1000usize, WINDOWS));
+
+ println!("{}", format_size(1_023_654_123_654_u64, BINARY));
+ println!("{}", format_size(123456789usize, DECIMAL));
+ println!("{}", format_size_i(-123456789, WINDOWS));
+
+ println!("{}", SizeFormatter::new(1234u32, BINARY));
+ println!("{}", ISizeFormatter::new(1234, BINARY));
+}