pub fn is_valid(id: &str) -> bool {
    // check the length
    if id.len() < 2 {
        return false;
    }

    let mut index: u32 = 0;
    let mut sum: u32 = 0;

    for c in id.chars().rev() {
        if c.is_whitespace() {
            continue;
        }

        let mut v: u32;

        match c.to_digit(10) {
            Some(d) => v = d,
            None => return false,
        }

        if index % 2 != 0 {
            v *= 2;

            if v > 9 {
                v -= 9;
            }

        }

        index += 1;
        sum += v;
    }

    if index < 2 {
        return false;
    }

    (sum % 10) == 0
}

pub fn is_valid(id: &str) -> bool {
    // check the length
    if id.len() < 2 {
        return false;
    }

    let mut index: u32 = 0;
    let mut number: Vec<u32> = Vec::new();

    for c in id.chars().rev() {
        if c.is_whitespace() {
            continue;
        }

        let mut v: u32;

        match c.to_digit(10) {
            Some(d) => v = d,
            None => return false,
        }

        if index % 2 != 0 {
            v *= 2;

            if v > 9 {
                v -= 9;
            }

        }

        index += 1;

        number.push(v);
    }

    if number.len() == 1 {
        return false;
    }

    let r: u32 = number.iter().sum();

    (r % 10) == 0
}

--- 
+++ 
@@ -5,7 +5,7 @@
     }
 
     let mut index: u32 = 0;
-    let mut number: Vec<u32> = Vec::new();
+    let mut sum: u32 = 0;
 
     for c in id.chars().rev() {
         if c.is_whitespace() {
@@ -29,15 +29,12 @@
         }
 
         index += 1;
-
-        number.push(v);
+        sum += v;
     }
 
-    if number.len() == 1 {
+    if index < 2 {
         return false;
     }
 
-    let r: u32 = number.iter().sum();
-
-    (r % 10) == 0
+    (sum % 10) == 0
 }
Change luhn code to simplify

I still not decide to use the functional style for this case
