Skip to content

Commit

Permalink
chore: use impl ToString and re-run coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGimbel committed Apr 19, 2024
1 parent e9fd604 commit 756c591
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
10 changes: 5 additions & 5 deletions assets/coverage/flat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::Rng;
pub mod data;

fn parse_args_to_vec(input: &str) -> Vec<&str> {
let args: Vec<&str> = input.split(",").collect();
let args: Vec<&str> = input.split(",").clone().collect();

Check warning on line 8 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

single-character string constant used as pattern

warning: single-character string constant used as pattern --> src/lib.rs:8:39 | 8 | let args: Vec<&str> = input.split(",").clone().collect(); | ^^^ help: consider using a `char`: `','` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern = note: `#[warn(clippy::single_char_pattern)]` on by default
return args;

Check warning on line 9 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> src/lib.rs:9:5 | 9 | return args; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 9 - return args; 9 + args |
}

Expand Down Expand Up @@ -107,15 +107,16 @@ pub fn gen_email() -> String {
///let word: String = gen_enum("some,random,words".to_string());
/// // word = "random"
/// ```
pub fn gen_enum(input: String) -> String {
let args = parse_args_to_vec(&input);
pub fn gen_enum(input: impl ToString) -> String {
let input_var = input.to_string();
let args = parse_args_to_vec(input_var.as_str());
let mut rnd = rand::thread_rng();
let mut index: usize = 0;
if args.len() - 1 > 0 {
index = rnd.gen_range(0..args.len() - 1);
}

return format!("{}", args[index]); //String::from(args[index]);
return format!("{}", args[index]);

Check warning on line 119 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `format!`

warning: useless use of `format!` --> src/lib.rs:119:12 | 119 | return format!("{}", args[index]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `args[index].to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format = note: `#[warn(clippy::useless_format)]` on by default

Check warning on line 119 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> src/lib.rs:119:5 | 119 | return format!("{}", args[index]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 119 - return format!("{}", args[index]); 119 + format!("{}", args[index]) |
}

/// Return random HTTP Method, taken from <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods>
Expand Down Expand Up @@ -157,10 +158,11 @@ pub fn gen_http_method() -> String {
///let i = gen_int("1,100".to_string()).parse::<i32>().unwrap();
/// assert!(i <= 100 && i >= 1)
/// ```
pub fn gen_int(input: String) -> String {
pub fn gen_int(input: impl ToString) -> String {
let mut i1: i32 = 0;
let mut i2: i32 = 0;
let args = parse_args_to_vec(&input);
let input_val = input.to_string();
let args = parse_args_to_vec(&input_val.as_str());

Check warning on line 165 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/lib.rs:165:34 | 165 | let args = parse_args_to_vec(&input_val.as_str()); | ^^^^^^^^^^^^^^^^^^^ help: change this to: `input_val.as_str()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
let mut rnd = rand::thread_rng();

if args.len() == 0 {

Check warning on line 168 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

length comparison to zero

warning: length comparison to zero --> src/lib.rs:168:8 | 168 | if args.len() == 0 { | ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `args.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default
Expand Down Expand Up @@ -259,7 +261,7 @@ mod tests {

#[test]
fn test_gen_enum() {
let mut words: String = gen_enum("hello,hola,hallo".to_string());
let mut words: String = gen_enum("hello,hola,hallo");
let mut res = match words.as_str() {
"hello" => true,
"hola" => true,
Expand All @@ -268,7 +270,7 @@ mod tests {
};
assert_eq!(true, res);

words = gen_enum("a,b,c,d,e,f,g,h,i,j".to_string());
words = gen_enum("a,b,c,d,e,f,g,h,i,j");
res = match words.as_str() {
"a" => true,
"b" => true,
Expand Down

0 comments on commit 756c591

Please sign in to comment.