Guest User

Untitled

a guest
Jul 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. enum Type {
  2. Visa,
  3. Discover,
  4. MasterCard,
  5. AmericanExpress
  6. }
  7.  
  8. impl ToString for Type {
  9. fn to_string(&self) -> String {
  10. match self {
  11. Type::Visa => "Visa".into(),
  12. Type::Discover => "Discover".into(),
  13. Type::MasterCard => "MasterCard".into(),
  14. Type::AmericanExpress => "AmericanExpress".into(),
  15. }
  16. }
  17. }
  18.  
  19. type Rule = (Type, Vec<Vec<String>>);
  20.  
  21. const RULES: Vec<Rule> = vec![
  22. (Type::Visa, vec![vec!["4"]]),
  23. (Type::Discover, vec![vec!["6011"], range_of_strings(622126, 622925), range_of_strings(644, 649), ["65"]]),
  24. (Type::MasterCard, vec![range_of_strings(50, 55), range_of_strings(222100, 272099)]),
  25. (Type::AmericanExpress, vec![vec!["34"], vec!["37"]]),
  26. ];
  27.  
  28. fn range_of_strings(start: u32, end: u32) -> Vec<String> {
  29. (start..=end).map(|n| n.to_string()).collect()
  30. }
  31.  
  32. fn card_matches_rule(card: String, rule: Rule) -> boolean {
  33.  
  34. }
  35.  
  36. fn to_matching_type(card: String, matched: Option<Type>, type: Type) -> Option<Type> {
  37.  
  38. }
  39.  
  40. fn detect_type(card: Option<String>) -> Maybe<Type> {
  41. return if card.is_none() { card } else {
  42.  
  43. }
  44. }
  45.  
  46. fn main() {
  47. println!("Hello, world!");
  48. }
Add Comment
Please, Sign In to add comment