Debian Codegraph @

src/formatters.rs

raw symbols SCIP
1 use libmrust-analyzer cargo libm 0.2.6 crate/::{fabsrust-analyzer cargo libm 0.2.6 math/fabs/fabs()., modfrust-analyzer cargo libm 0.2.6 math/modf/modf().};
2
3 use craterust-analyzer cargo humansize 2.1.3 crate/::{scalesrust-analyzer cargo humansize 2.1.3 scales/, utilsrust-analyzer cargo humansize 2.1.3 utils/::f64_eqrust-analyzer cargo humansize 2.1.3 utils/f64_eq()., BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#, FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#, Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#, ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64#, Unsignedrust-analyzer cargo humansize 2.1.3 numeric_traits/Unsigned#};
4
5 pub struct ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#<T: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> {
6 valuerust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#value.: T,
7 optionsrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#options.: O,
8 }
9
10 impl<V: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#<V, O> {
11 pub fn newrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<V, O>`]new().(value: V, options: O) -> Selfrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<V, O>`] {
12 ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter# { valuerust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#value., optionsrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#options. }
13 }
14 }
15
16 impl<T: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#<T, O> {
17 fn fmtrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<T, O>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
18 let opts = self.optionsrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#options..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().();
19 let divider = opts.kilorust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#kilo..valuerust-analyzer cargo humansize 2.1.3 options/impl#[Kilo]value().();
20
21 let mut size: f64 = self.valuerust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#value..to_f64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64#to_f64().();
22 let mut scale_idx = 0;
23
24 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) = opts.fixed_atrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#fixed_at. {
25 while scale_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().val as usize {
26 size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign().divider;
27 scale_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
28 }
29 } else {
30 while fabsrust-analyzer cargo libm 0.2.6 math/fabs/fabs().(size) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge().divider {
31 size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign().divider;
32 scale_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
33 }
34 }
35
36 let mut scale = match (opts.unitsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#units., opts.long_unitsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#long_units., opts.base_unitrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#base_unit.) {
37 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Decimalrust-analyzer cargo humansize 2.1.3 options/Kilo#Decimal#, false, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Byterust-analyzer cargo humansize 2.1.3 options/BaseUnit#Byte#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_DECIMALrust-analyzer cargo humansize 2.1.3 scales/SCALE_DECIMAL.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
38 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Decimalrust-analyzer cargo humansize 2.1.3 options/Kilo#Decimal#, true, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Byterust-analyzer cargo humansize 2.1.3 options/BaseUnit#Byte#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_DECIMAL_LONGrust-analyzer cargo humansize 2.1.3 scales/SCALE_DECIMAL_LONG.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
39 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Binaryrust-analyzer cargo humansize 2.1.3 options/Kilo#Binary#, false, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Byterust-analyzer cargo humansize 2.1.3 options/BaseUnit#Byte#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_BINARYrust-analyzer cargo humansize 2.1.3 scales/SCALE_BINARY.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
40 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Binaryrust-analyzer cargo humansize 2.1.3 options/Kilo#Binary#, true, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Byterust-analyzer cargo humansize 2.1.3 options/BaseUnit#Byte#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_BINARY_LONGrust-analyzer cargo humansize 2.1.3 scales/SCALE_BINARY_LONG.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
41 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Decimalrust-analyzer cargo humansize 2.1.3 options/Kilo#Decimal#, false, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_DECIMAL_BITrust-analyzer cargo humansize 2.1.3 scales/SCALE_DECIMAL_BIT.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
42 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Decimalrust-analyzer cargo humansize 2.1.3 options/Kilo#Decimal#, true, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_DECIMAL_BIT_LONGrust-analyzer cargo humansize 2.1.3 scales/SCALE_DECIMAL_BIT_LONG.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
43 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Binaryrust-analyzer cargo humansize 2.1.3 options/Kilo#Binary#, false, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_BINARY_BITrust-analyzer cargo humansize 2.1.3 scales/SCALE_BINARY_BIT.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
44 (Kilorust-analyzer cargo humansize 2.1.3 options/Kilo#::Binaryrust-analyzer cargo humansize 2.1.3 options/Kilo#Binary#, true, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit#) => scalesrust-analyzer cargo humansize 2.1.3 scales/::SCALE_BINARY_BIT_LONGrust-analyzer cargo humansize 2.1.3 scales/SCALE_BINARY_BIT_LONG.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().scale_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
45 };
46
47 // Remove "s" from the scale if the size is 1.x
48 let (fpart, ipart) = modfrust-analyzer cargo libm 0.2.6 math/modf/modf().(size);
49 if f64_eqrust-analyzer cargo humansize 2.1.3 utils/f64_eq().(ipart, 1.0)
50 && (opts.long_unitsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#long_units. || (opts.base_unitrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#base_unit. rust-analyzer cargo humansize 2.1.3 options/impl#[BaseUnit][`PartialEq<Self>`]eq().==rust-analyzer cargo humansize 2.1.3 options/impl#[BaseUnit][`PartialEq<Self>`]eq(). rust-analyzer cargo humansize 2.1.3 options/impl#[BaseUnit][`PartialEq<Self>`]eq().BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit# && scale_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0))
51 {
52 scale = &scale[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#scale.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
53 }
54
55 let places = if f64_eqrust-analyzer cargo humansize 2.1.3 utils/f64_eq().(fpart, 0.0) {
56 opts.decimal_zeroesrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#decimal_zeroes.
57 } else {
58 opts.decimal_placesrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#decimal_places.
59 };
60
61 let space = if opts.space_after_valuerust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#space_after_value. { " " } else { "" };
62
63 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:.*}{}{}{}", places, size, space, scale, opts.suffixrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#suffix.)
64 }
65 }
66
67 impl<'a, U: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64# + Unsignedrust-analyzer cargo humansize 2.1.3 numeric_traits/Unsigned# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#<U, O>>
68 for ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#<U, &'a O>
69 {
70 fn fromrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<U, &'a O>`][`From<&'a SizeFormatter<U, O>>`]from().(source: &'a SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#<U, O>) -> Selfrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<U, &'a O>`][`From<&'a SizeFormatter<U, O>>`] {
71 ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter# {
72 valuerust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#value.: source.valuerust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#value.,
73 optionsrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#options.: &source.optionsrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#options.,
74 }
75 }
76 }
77
78 pub struct SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#<T: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64# + Unsignedrust-analyzer cargo humansize 2.1.3 numeric_traits/Unsigned#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> {
79 valuerust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#value.: T,
80 optionsrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#options.: O,
81 }
82
83 impl<V: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64# + Unsignedrust-analyzer cargo humansize 2.1.3 numeric_traits/Unsigned#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#>> SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#<V, O> {
84 pub fn newrust-analyzer cargo humansize 2.1.3 formatters/impl#[`SizeFormatter<V, O>`]new().(value: V, options: O) -> Selfrust-analyzer cargo humansize 2.1.3 formatters/impl#[`SizeFormatter<V, O>`] {
85 SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter# { valuerust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#value., optionsrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#options. }
86 }
87 }
88
89 impl<T: ToF64rust-analyzer cargo humansize 2.1.3 numeric_traits/ToF64# + Unsignedrust-analyzer cargo humansize 2.1.3 numeric_traits/Unsigned# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#, O: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#> + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#
90 for SizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/SizeFormatter#<T, O>
91 {
92 fn fmtrust-analyzer cargo humansize 2.1.3 formatters/impl#[`SizeFormatter<T, O>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
93 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", ISizeFormatterrust-analyzer cargo humansize 2.1.3 formatters/ISizeFormatter#::fromrust-analyzer cargo humansize 2.1.3 formatters/impl#[`ISizeFormatter<U, &'a O>`][`From<&'a SizeFormatter<U, O>>`]from().(self))
94 }
95 }