Skip to content

Commit

Permalink
troca ifs por matches
Browse files Browse the repository at this point in the history
  • Loading branch information
brenomfviana committed Jul 30, 2024
1 parent db47733 commit 10450e3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
7 changes: 3 additions & 4 deletions brado/src/certidao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 {

let rest: u16 = d % 11;

if rest > 9 {
1
} else {
rest
match rest > 9 {
true => 1,
false => rest,
}
}

Expand Down
21 changes: 9 additions & 12 deletions brado/src/cnh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ fn generate_first_digit(doc_slice: &[u16]) -> (u16, u16) {

let rest: u16 = sum % 11;

if rest >= 10 {
(0, 2)
} else {
(rest, 0)
match rest >= 10 {
true => (0, 2),
false => (rest, 0),
}
}

Expand All @@ -85,16 +84,14 @@ fn generate_second_digit(
}

let rest: u16 = sum % 11;
let second: u16 = if rest >= dsc {
rest - dsc
} else {
11 + rest - dsc
let second: u16 = match rest >= dsc {
true => rest - dsc,
false => 11 + rest - dsc,
};

if second >= 10 {
0
} else {
second
match second >= 10 {
true => 0,
false => second,
}
}

Expand Down
9 changes: 9 additions & 0 deletions brado/src/cnpj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ use crate::common::{get_digits, get_symbols, random_digit_vector, to_decimal};

const CNPJ_SIZE: usize = 14;

/// Converte um caractere em um dígito válido de CNPJ.
///
/// CNPJ Alfanumérico: SS.SSS.SSS/SSSS-NN,
/// onde N: Número; S: Letra ou Número.
///
/// A validação permanece igual, porém, é necessário
/// substituir os caracteres pelos valores respectivos
/// da tabela ASCII e dele subtrair 48. Assim, '0'=0,
/// '1'=1, ..., 'A'=17, 'B'=18, ...
fn to_cnpj_digit(
i: usize,
c: char,
Expand Down
14 changes: 6 additions & 8 deletions brado/src/eleitoral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ fn generate_first_digit(doc_slice: &[u16]) -> u16 {

let rest: u16 = sum % 11;

if rest == 10 {
0
} else {
rest
match rest {
10 => 0,
_ => rest,
}
}

Expand All @@ -92,10 +91,9 @@ fn generate_second_digit(

let rest: u16 = sum % 11;

if rest == 10 {
0
} else {
rest
match rest {
10 => 0,
_ => rest,
}
}

Expand Down
7 changes: 3 additions & 4 deletions brado/src/nis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 {

let rest: u16 = sum % 11;

if rest >= 2 {
11 - rest
} else {
0
match rest >= 2 {
true => 11 - rest,
false => 0,
}
}

Expand Down
7 changes: 3 additions & 4 deletions brado/src/renavam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 {

let rest: u16 = (sum * 10) % 11;

if rest == 10 {
0
} else {
rest
match rest {
10 => 0,
_ => rest,
}
}

Expand Down

0 comments on commit 10450e3

Please sign in to comment.