Skip to content

Commit

Permalink
chore: Reformatted with rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejiah committed Sep 28, 2023
1 parent 66e5cda commit 296639d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions fake/src/faker/impls/finance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ALPHABET: &[char; 26] = &[

const ALPHANUMERIC: &[char; 36] = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
];

const ISO3166: &[&str] = &[
Expand Down Expand Up @@ -78,13 +78,18 @@ impl<L: Data> Dummy<Bic<L>> for String {
}

fn split_number_to_digits(x: u32) -> Vec<u32> {
x.to_string().chars().map(|x| x.to_digit(10).unwrap()).collect::<Vec<u32>>()
x.to_string()
.chars()
.map(|x| x.to_digit(10).unwrap())
.collect::<Vec<u32>>()
}

impl<L: Data> Dummy<Isin<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Isin<L>, rng: &mut R) -> Self {
let country_code = *ISO3166.choose(rng).unwrap();
let nsin = (1..10).map(|_x| *ALPHANUMERIC.choose(rng).unwrap()).collect::<String>();
let nsin = (1..10)
.map(|_x| *ALPHANUMERIC.choose(rng).unwrap())
.collect::<String>();
// Checksum calculation according to Luhn algorithm
let char_to_num: Vec<u32> = country_code
.chars()
Expand All @@ -98,18 +103,15 @@ impl<L: Data> Dummy<Isin<L>> for String {
})
.flat_map(split_number_to_digits)
.collect();
let checksum_even = char_to_num.iter()
.rev()
.skip(1)
.step_by(2)
.sum::<u32>();
let checksum_odd = char_to_num.iter()
let checksum_even = char_to_num.iter().rev().skip(1).step_by(2).sum::<u32>();
let checksum_odd = char_to_num
.iter()
.rev()
.step_by(2)
.map(|&x| x * 2)
.flat_map(split_number_to_digits)
.sum::<u32>();
let checksum_digit = (10 - ((checksum_even + checksum_odd) % 10)) % 10;
return format!("{}{}{}", country_code, nsin, checksum_digit)
return format!("{}{}{}", country_code, nsin, checksum_digit);

Check failure on line 115 in fake/src/faker/impls/finance.rs

View workflow job for this annotation

GitHub Actions / Clippy

unneeded `return` statement
}
}
2 changes: 1 addition & 1 deletion fake/src/faker/impls/internet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::faker::lorem::raw::Word;
use crate::faker::name::raw::FirstName;
use crate::locales::Data;
use crate::{Dummy, Fake, Faker};
use deunicode::AsciiChars;
use rand::distributions::{Distribution, Uniform};
use rand::seq::SliceRandom;
use rand::Rng;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use deunicode::AsciiChars;

impl<L: Data> Dummy<FreeEmailProvider<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(_: &FreeEmailProvider<L>, rng: &mut R) -> Self {
Expand Down

0 comments on commit 296639d

Please sign in to comment.