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

    // This is the number of leading "z" characters.
    //
    // For values of `i` less than 26^2 - 26, the returned string is
    // just the radix 26 representation of that number with a width of
    // two (using the lowercase ASCII characters as the digits).
    //
    // * if `i` is 26^2 - 26, then the returned string is "zaa",
    // * if `i` is 26^3 - 26, then the returned string is "zzaaaa",
    // * if `i` is 26^4 - 26, then the returned string is "zzzaaaaa",
    //
    // and so on. As you can see, the number of leading "z"s 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 "z" characters.
    let width = d + 1;

    // This is the radix 10 number to render in radix 26, to the right
    // of the leading "z"s.
    let number = (i + 26) - 26_usize.pow(d as u32);

    // This is the radix 26 number to render after the leading "z"s,
    // collected in a `String`.
    //
    // For example, if `i` is 789, then `number` is 789 + 26 - 676,
    // which equals 139. In radix 26 and assuming a `width` of 3, this
    // number is
    //
    //     [0, 5, 9]
    //
    // with the most significant digit on the left and the least
    // significant digit on the right. After translating to ASCII
    // lowercase letters, this becomes "afj".
    let digits = str_prefix_fixed_width(number, width)?;

    // `empty` is just the empty string, to be displayed with a width
    // of `num_fill_chars` and with blank spaces filled with the
    // character "z".
    //
    // `digits` is as described in the previous comment.
    Some(format!(
        "{empty:z<num_fill_chars$}{digits}",
        empty = "",
        num_fill_chars = num_fill_chars,
        digits = digits
    ))
}
/// Dynamically sized alphabetic 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::str_prefix;
///
/// assert_eq!(str_prefix(0), "aa");
/// assert_eq!(str_prefix(649), "yz");
/// assert_eq!(str_prefix(650), "zaaa");
/// assert_eq!(str_prefix(651), "zaab");
/// ```
Dynamically sized alphabetic 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 alphabetic string representation of index ` i ` . The size of the returned string starts at two then grows by 2 if ` i ` is sufficiently large .
fn str_prefix(i: usize) -> Option<String> {
    // This number tells us the order of magnitude of `i`, with a
    // slight adjustment.
    //
    // We shift by 26 so that
    //
    // * if `i` is in the interval [0, 26^2 - 26), then `d` is 1,
    // * if `i` is in the interval [26^2 - 26, 26^3 - 26), then `d` is 2,
    // * if `i` is in the interval [26^3 - 26, 26^4 - 26), then `d` is 3,
    //
    // and so on. This will allow us to compute how many leading "z"
    // characters need to appear in the string and how many characters
    // to format to the right of those.
    let d = log26(i + 26);
    // This is the number of leading "z" characters.
    //
    // For values of `i` less than 26^2 - 26, the returned string is
    // just the radix 26 representation of that number with a width of
    // two (using the lowercase ASCII characters as the digits).
    //
    // * if `i` is 26^2 - 26, then the returned string is "zaa",
    // * if `i` is 26^3 - 26, then the returned string is "zzaaaa",
    // * if `i` is 26^4 - 26, then the returned string is "zzzaaaaa",
    //
    // and so on. As you can see, the number of leading "z"s 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 "z" characters.
    let width = d + 1;
    // This is the radix 10 number to render in radix 26, to the right
    // of the leading "z"s.
    let number = (i + 26) - 26_usize.pow(d as u32);
    // This is the radix 26 number to render after the leading "z"s,
    // collected in a `String`.
    //
    // For example, if `i` is 789, then `number` is 789 + 26 - 676,
    // which equals 139. In radix 26 and assuming a `width` of 3, this
    // number is
    //
    //     [0, 5, 9]
    //
    // with the most significant digit on the left and the least
    // significant digit on the right. After translating to ASCII
    // lowercase letters, this becomes "afj".
    let digits = str_prefix_fixed_width(number, width)?;
    // `empty` is just the empty string, to be displayed with a width
    // of `num_fill_chars` and with blank spaces filled with the
    // character "z".
    //
    // `digits` is as described in the previous comment.
    Some(format!(
        "{empty:z<num_fill_chars$}{digits}",
        empty = "",
        num_fill_chars = num_fill_chars,
        digits = digits
    ))
}
fn str_prefix ( i : usize ) -> Option < String > { // This number tells us the order of magnitude of `i`, with a // slight adjustment. // // We shift by 26 so that // // * if `i` is in the interval [0, 26^2 - 26), then `d` is 1, // * if `i` is in the interval [26^2 - 26, 26^3 - 26), then `d` is 2, // * if `i` is in the interval [26^3 - 26, 26^4 - 26), then `d` is 3, // // and so on. This will allow us to compute how many leading "z" // characters need to appear in the string and how many characters // to format to the right of those. let d = log26 ( i + 26 ) ; // This is the number of leading "z" characters. // // For values of `i` less than 26^2 - 26, the returned string is // just the radix 26 representation of that number with a width of // two (using the lowercase ASCII characters as the digits). // // * if `i` is 26^2 - 26, then the returned string is "zaa", // * if `i` is 26^3 - 26, then the returned string is "zzaaaa", // * if `i` is 26^4 - 26, then the returned string is "zzzaaaaa", // // and so on. As you can see, the number of leading "z"s 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 "z" characters. let width = d + 1 ; // This is the radix 10 number to render in radix 26, to the right // of the leading "z"s. let number = ( i + 26 ) - 26_usize . pow ( d as u32 ) ; // This is the radix 26 number to render after the leading "z"s, // collected in a `String`. // // For example, if `i` is 789, then `number` is 789 + 26 - 676, // which equals 139. In radix 26 and assuming a `width` of 3, this // number is // //     [0, 5, 9] // // with the most significant digit on the left and the least // significant digit on the right. After translating to ASCII // lowercase letters, this becomes "afj". let digits = str_prefix_fixed_width ( number , width ) ? ; // `empty` is just the empty string, to be displayed with a width // of `num_fill_chars` and with blank spaces filled with the // character "z". // // `digits` is as described in the previous comment. Some ( format ! ( " " empty " " num_fill_chars num_fill_chars digits digits ) ) }
Dynamically sized alphabetic string representation of index `i`.
Dynamically sized alphabetic string representation of index ` i ` .
i
usize
i
usize
examples
```rust,ignore
use crate::filenames::str_prefix.


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