1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Byte-size constants, because Rust has none.
//!
//! A byte bound written as `64 * 1024 * 1024` is read by counting zeros, and
//! the standard library offers no constant or unit type to write it any other
//! way. These do, and they compose: `96 * MIB`, `2 * GIB`.
//!
//! Two families, differing only in type. A limit compared against a database
//! counter is `i64`; a length compared against `Vec::len` is `usize`. Casting
//! between them in a `const` buys nothing but a lint, so both exist and each
//! is named for what it measures.
/// One kibibyte, for values compared against database counters.
pub const KIB: i64 = 1024;
/// One mebibyte, for values compared against database counters.
pub const MIB: i64 = KIB * 1024;
/// One gibibyte, for values compared against database counters.
pub const GIB: i64 = MIB * 1024;
/// One kibibyte, for values compared against in-memory lengths.
pub const KIB_LEN: usize = 1024;
/// One mebibyte, for values compared against in-memory lengths.
pub const MIB_LEN: usize = KIB_LEN * 1024;
/// One gibibyte, for values compared against in-memory lengths.
pub const GIB_LEN: usize = MIB_LEN * 1024;