File: new_prefix.rs

package info (click to toggle)
rust-size-format 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: makefile: 4
file content (49 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download
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
extern crate generic_array;
extern crate size_format;

use generic_array::{typenum::U3, GenericArray};
use size_format::{PointSeparated, PrefixType, SizeFormatter};

struct Millimeter;

impl PrefixType for Millimeter {
    type N = U3;

    const PREFIX_SIZE: u32 = 1000;

    fn prefixes() -> GenericArray<&'static str, Self::N> {
        ["m", "", "k"].into()
    }
}

#[test]
fn new_prefix_works() {
    assert_eq!(
        format!(
            "{}m",
            SizeFormatter::<u32, Millimeter, PointSeparated>::new(1)
        ),
        "1mm".to_string()
    );
    assert_eq!(
        format!(
            "{}m",
            SizeFormatter::<u32, Millimeter, PointSeparated>::new(1_000)
        ),
        "1.0m".to_string()
    );
    assert_eq!(
        format!(
            "{}m",
            SizeFormatter::<u32, Millimeter, PointSeparated>::new(1_000_000)
        ),
        "1.0km".to_string()
    );
    assert_eq!(
        format!(
            "{}m",
            SizeFormatter::<u64, Millimeter, PointSeparated>::new(10_000_000_000)
        ),
        "10000.0km".to_string()
    );
}