You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
624 B
Rust
23 lines
624 B
Rust
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
//
|
|
// Copyright (c) 2020-2022 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
//! General purpose code.
|
|
|
|
/// Convert a size into human readable format.
|
|
pub const fn size_human_readable_ceil(size: usize) -> (usize, &'static str) {
|
|
const KIB: usize = 1024;
|
|
const MIB: usize = 1024 * 1024;
|
|
const GIB: usize = 1024 * 1024 * 1024;
|
|
|
|
if (size / GIB) > 0 {
|
|
(size.div_ceil(GIB), "GiB")
|
|
} else if (size / MIB) > 0 {
|
|
(size.div_ceil(MIB), "MiB")
|
|
} else if (size / KIB) > 0 {
|
|
(size.div_ceil(KIB), "KiB")
|
|
} else {
|
|
(size, "Byte")
|
|
}
|
|
}
|