#[non_exhaustive]
pub struct FormatSizeOptions { pub base_unit: BaseUnit, pub kilo: Kilo, pub units: Kilo, pub decimal_places: usize, pub decimal_zeroes: usize, pub fixed_at: Option<FixedAt>, pub long_units: bool, pub space_after_value: bool, pub suffix: &'static str, }
Expand description

Holds the options for the file_size method.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§base_unit: BaseUnit

Whether the value being formatted represents an amount of bits or bytes.

§kilo: Kilo

The scale (binary/decimal) to divide against.

§units: Kilo

The unit set to display.

§decimal_places: usize

The amount of decimal places to display if the decimal part is non-zero.

§decimal_zeroes: usize

The amount of zeroes to display if the decimal part is zero.

§fixed_at: Option<FixedAt>

Whether to force a certain representation and if so, which one.

§long_units: bool

Whether to use the full unit (e.g. Kilobyte) or its abbreviation (kB).

§space_after_value: bool

Whether to place a space between value and units.

§suffix: &'static str

An optional suffix which will be appended after the unit. Useful to represent speeds (e.g. `1 kB/s)

Implementations§

Examples found in repository?
examples/custom_options.rs (line 6)
4
5
6
7
8
9
10
fn main() {
    // Create a new FormatSizeOptions struct starting from one of the defaults
    let custom_options = FormatSizeOptions::from(DECIMAL).decimal_places(5);

    // Then use it
    println!("{}", format_size(3024usize, custom_options));
}
Examples found in repository?
examples/custom_options.rs (line 6)
4
5
6
7
8
9
10
fn main() {
    // Create a new FormatSizeOptions struct starting from one of the defaults
    let custom_options = FormatSizeOptions::from(DECIMAL).decimal_places(5);

    // Then use it
    println!("{}", format_size(3024usize, custom_options));
}

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.