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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* SPDX-FileCopyrightText: 2023 Tommaso Fontana
* SPDX-FileCopyrightText: 2023 Inria
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
*/
/// Given a size in bytes, returns it in a human-readable format using SI-prefixed units.
///
/// # Examples
///
/// ```rust
/// use mem_dbg::humanize_float;
///
/// let (x, uom) = humanize_float(100);
/// assert_eq!(x, 100.0);
/// assert_eq!(uom, " B");
///
/// let (x, uom) = humanize_float(1234);
/// assert_eq!(x, 1.234);
/// assert_eq!(uom, "kB");
///
/// let (x, uom) = humanize_float(0);
/// assert_eq!(x, 0.0);
/// assert_eq!(uom, " B");
///
/// let (x, uom) = humanize_float(usize::MAX);
/// assert!(x > 1.0);
/// #[cfg(target_pointer_width = "64")]
/// assert_eq!(uom, "EB");
/// #[cfg(target_pointer_width = "32")]
/// assert_eq!(uom, "GB");
/// ```
pub const
/// Returns the color code corresponding to the size.
///
/// # Examples
///
/// ```rust
/// use mem_dbg::color;
/// use mem_dbg::reset_color;
///
/// assert_eq!(color(100), reset_color());
/// assert_eq!(color(1000), "\x1B[32m");
/// assert_eq!(color(1_000_000), "\x1B[33m");
/// assert_eq!(color(1_000_000_000), "\x1B[31m");
/// ```
pub const
/// Returns the color used to print types.
///
/// # Examples
///
/// ```rust
/// use mem_dbg::type_color;
///
/// assert_eq!(type_color(), "\x1B[38;2;128;128;128m");
/// ```
pub const
/// Returns the color code to reset the color.
///
/// # Examples
///
/// ```rust
/// use mem_dbg::reset_color;
///
/// assert_eq!(reset_color(), "\x1B[0m");
/// ```
pub const
/// Returns the color used to print reference addresses (first encounter).
///
/// # Examples
///
/// ```rust
/// use mem_dbg::ref_color;
///
/// assert_eq!(ref_color(), "\x1B[36m");
/// ```
pub const
/// Returns the color used to print back-reference arrows (subsequent encounters).
///
/// # Examples
///
/// ```rust
/// use mem_dbg::backref_color;
///
/// assert_eq!(backref_color(), "\x1B[35m");
/// ```
pub const
/// Returns the number of digits of a number.
///
/// ```
/// use mem_dbg::n_of_digits;
///
/// assert_eq!(n_of_digits(0), 1);
/// assert_eq!(n_of_digits(1), 1);
/// assert_eq!(n_of_digits(10), 2);
/// assert_eq!(n_of_digits(100), 3);
/// assert_eq!(n_of_digits(1000), 4);
/// assert_eq!(n_of_digits(10000), 5);
/// assert_eq!(n_of_digits(100000), 6);
/// ```
pub const