fn num_prefix(i: usize) -> String {
    // This number tells us the order of magnitude of `i`, with a
    // slight adjustment.
    //
    // We shift by 10 so that
    //
    // * if `i` is in the interval [0, 90), then `d` is 1,
    // * if `i` is in the interval [90, 990), then `d` is 2,
    // * if `i` is in the interval [990, 9990), then `d` is 3,
    //
    // and so on. This will allow us to compute how many leading "9"
    // characters need to appear in the string and how many digits to
    // format to the right of those.
    let d = log10(i + 10);

    // This is the number of leading "9" characters.
    //
    // For values of `i` less than 90, the returned string is just
    // that number padded by a 0 to ensure the width is 2, but
    //
    // * if `i` is 90, then the returned string is "900",
    // * if `i` is 990, then the returned string is "990000",
    // * if `i` is 9990, then the returned string is "99900000",
    //
    // and so on. As you can see, the number of leading 9s there is
    // linearly increasing by 1 for each order of magnitude.
    let num_fill_chars = d - 1;

    // This is the number of characters after the leading "9" characters.
    let width = d + 1;

    // This is the number to render after the leading "9"s.
    //
    // For example, if `i` is 5732, then the returned string is
    // "994742". After the two "9" characters is the number 4742,
    // which equals 5732 + 10 - 1000.
    let number = (i + 10) - 10_usize.pow(d as u32);

    // `empty` is just the empty string, to be displayed with a width
    // of `num_fill_chars` and with blank spaces filled with the
    // character "9".
    //
    // `number` is the next remaining part of the number to render;
    // for small numbers we pad with 0 and enforce a minimum width.
    format!(
        "{empty:9<num_fill_chars$}{number:0width$}",
        empty = "",
        num_fill_chars = num_fill_chars,
        number = number,
        width = width
    )
}
/// Dynamically sized numeric string representation of index `i`.
///
/// The size of the returned string starts at two then grows by 2 if
/// `i` is sufficiently large.
///
/// # Examples
///
/// ```rust,ignore
/// use crate::filenames::num_prefix;
///
/// assert_eq!(num_prefix(89), "89");
/// assert_eq!(num_prefix(90), "9000");
/// assert_eq!(num_prefix(91), "9001");
/// ```
Dynamically sized numeric string representation of index `i`.
The size of the returned string starts at two then grows by 2 if
`i` is sufficiently large.
Dynamically sized numeric string representation of index ` i ` . The size of the returned string starts at two then grows by 2 if ` i ` is sufficiently large .
fn num_prefix(i: usize) -> String {
    // This number tells us the order of magnitude of `i`, with a
    // slight adjustment.
    //
    // We shift by 10 so that
    //
    // * if `i` is in the interval [0, 90), then `d` is 1,
    // * if `i` is in the interval [90, 990), then `d` is 2,
    // * if `i` is in the interval [990, 9990), then `d` is 3,
    //
    // and so on. This will allow us to compute how many leading "9"
    // characters need to appear in the string and how many digits to
    // format to the right of those.
    let d = log10(i + 10);
    // This is the number of leading "9" characters.
    //
    // For values of `i` less than 90, the returned string is just
    // that number padded by a 0 to ensure the width is 2, but
    //
    // * if `i` is 90, then the returned string is "900",
    // * if `i` is 990, then the returned string is "990000",
    // * if `i` is 9990, then the returned string is "99900000",
    //
    // and so on. As you can see, the number of leading 9s there is
    // linearly increasing by 1 for each order of magnitude.
    let num_fill_chars = d - 1;
    // This is the number of characters after the leading "9" characters.
    let width = d + 1;
    // This is the number to render after the leading "9"s.
    //
    // For example, if `i` is 5732, then the returned string is
    // "994742". After the two "9" characters is the number 4742,
    // which equals 5732 + 10 - 1000.
    let number = (i + 10) - 10_usize.pow(d as u32);
    // `empty` is just the empty string, to be displayed with a width
    // of `num_fill_chars` and with blank spaces filled with the
    // character "9".
    //
    // `number` is the next remaining part of the number to render;
    // for small numbers we pad with 0 and enforce a minimum width.
    format!(
        "{empty:9<num_fill_chars$}{number:0width$}",
        empty = "",
        num_fill_chars = num_fill_chars,
        number = number,
        width = width
    )
}
fn num_prefix ( i : usize ) -> String { // This number tells us the order of magnitude of `i`, with a // slight adjustment. // // We shift by 10 so that // // * if `i` is in the interval [0, 90), then `d` is 1, // * if `i` is in the interval [90, 990), then `d` is 2, // * if `i` is in the interval [990, 9990), then `d` is 3, // // and so on. This will allow us to compute how many leading "9" // characters need to appear in the string and how many digits to // format to the right of those. let d = log10 ( i + 10 ) ; // This is the number of leading "9" characters. // // For values of `i` less than 90, the returned string is just // that number padded by a 0 to ensure the width is 2, but // // * if `i` is 90, then the returned string is "900", // * if `i` is 990, then the returned string is "990000", // * if `i` is 9990, then the returned string is "99900000", // // and so on. As you can see, the number of leading 9s there is // linearly increasing by 1 for each order of magnitude. let num_fill_chars = d - 1 ; // This is the number of characters after the leading "9" characters. let width = d + 1 ; // This is the number to render after the leading "9"s. // // For example, if `i` is 5732, then the returned string is // "994742". After the two "9" characters is the number 4742, // which equals 5732 + 10 - 1000. let number = ( i + 10 ) - 10_usize . pow ( d as u32 ) ; // `empty` is just the empty string, to be displayed with a width // of `num_fill_chars` and with blank spaces filled with the // character "9". // // `number` is the next remaining part of the number to render; // for small numbers we pad with 0 and enforce a minimum width. format ! ( " " empty " " num_fill_chars num_fill_chars number number width width ) }
Dynamically sized numeric string representation of index `i`.
Dynamically sized numeric string representation of index ` i ` .
i
usize
i
usize
examples
```rust,ignore
use crate::filenames::num_prefix.


` ` ` rust ignore use crate :: filenames :: num_prefix .