fn luhn(value: String) -> u8 {
    let checksum = value
        .chars()
        .map(|c| c.to_digit(10).unwrap_or(0))
        .enumerate()
        .fold(0, |acc, (idx, v)| {
            let value = if idx % 2 == 0 { v * 2 } else { v };
            acc + if value > 9 { value - 9 } else { value }
        });

    (10 - (checksum as u8 % 10)) % 10
}
/// Calculate the checksum based on luhn algorithm. See more information here:
/// https://en.wikipedia.org/wiki/Luhn_algorithm.
Calculate the checksum based on luhn algorithm.
Calculate the checksum based on luhn algorithm .
fn luhn(value: String) -> u8 {
    let checksum = value
        .chars()
        .map(|c| c.to_digit(10).unwrap_or(0))
        .enumerate()
        .fold(0, |acc, (idx, v)| {
            let value = if idx % 2 == 0 { v * 2 } else { v };
            acc + if value > 9 { value - 9 } else { value }
        });
    (10 - (checksum as u8 % 10)) % 10
}
fn luhn ( value : String ) -> u8 { let checksum = value . chars ( ) . map ( | c | c . to_digit ( 10 ) . unwrap_or ( 0 ) ) . enumerate ( ) . fold ( 0 , | acc , ( idx , v ) | { let value = if idx % 2 == 0 { v * 2 } else { v } ; acc + if value > 9 { value - 9 } else { value } } ) ; ( 10 - ( checksum as u8 % 10 ) ) % 10 }
Calculate the checksum based on luhn algorithm.
Calculate the checksum based on luhn algorithm .
value
String
value
String