Skip to content

Commit e6b4137

Browse files
committed
feat: implemented conversion methods such as as_mb()
1 parent ac756bb commit e6b4137

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

src/lib.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,84 @@ impl ByteSize {
243243
ByteSize(size * EIB)
244244
}
245245

246-
/// Returns byte count.
246+
/// Returns raw byte count.
247247
#[inline(always)]
248248
pub const fn as_u64(&self) -> u64 {
249249
self.0
250250
}
251251

252+
/// Returns byte count as kilobytes.
253+
#[inline(always)]
254+
pub const fn as_kb(&self) -> f64 {
255+
self.0 as f64 / KB as f64
256+
}
257+
258+
/// Returns byte count as kibibytes.
259+
#[inline(always)]
260+
pub const fn as_kib(&self) -> f64 {
261+
self.0 as f64 / KIB as f64
262+
}
263+
264+
/// Returns byte count as megabytes.
265+
#[inline(always)]
266+
pub const fn as_mb(&self) -> f64 {
267+
self.0 as f64 / MB as f64
268+
}
269+
270+
/// Returns byte count as mebibytes.
271+
#[inline(always)]
272+
pub const fn as_mib(&self) -> f64 {
273+
self.0 as f64 / MIB as f64
274+
}
275+
276+
/// Returns byte count as gigabytes.
277+
#[inline(always)]
278+
pub const fn as_gb(&self) -> f64 {
279+
self.0 as f64 / GB as f64
280+
}
281+
282+
/// Returns byte count as gibibytes.
283+
#[inline(always)]
284+
pub const fn as_gib(&self) -> f64 {
285+
self.0 as f64 / GIB as f64
286+
}
287+
288+
/// Returns byte count as terabytes.
289+
#[inline(always)]
290+
pub const fn as_tb(&self) -> f64 {
291+
self.0 as f64 / TB as f64
292+
}
293+
294+
/// Returns byte count as tebibytes.
295+
#[inline(always)]
296+
pub const fn as_tib(&self) -> f64 {
297+
self.0 as f64 / TIB as f64
298+
}
299+
300+
/// Returns byte count as petabytes.
301+
#[inline(always)]
302+
pub const fn as_pb(&self) -> f64 {
303+
self.0 as f64 / PB as f64
304+
}
305+
306+
/// Returns byte count as pebibytes.
307+
#[inline(always)]
308+
pub const fn as_pib(&self) -> f64 {
309+
self.0 as f64 / PB as f64
310+
}
311+
312+
/// Returns byte count as exabytes.
313+
#[inline(always)]
314+
pub const fn as_eb(&self) -> f64 {
315+
self.0 as f64 / EB as f64
316+
}
317+
318+
/// Returns byte count as exbibytes.
319+
#[inline(always)]
320+
pub const fn as_eib(&self) -> f64 {
321+
self.0 as f64 / EIB as f64
322+
}
323+
252324
/// Returns a formatting display wrapper.
253325
pub fn display(&self) -> Display {
254326
Display {

0 commit comments

Comments
 (0)