From 4c0c73b858b3ffaeb58bc0bfa09db5a76826119e Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Wed, 30 Aug 2023 20:46:40 -0300 Subject: [PATCH] clippy-fix --- dump-parser/src/mongodb/mod.rs | 2 +- dump-parser/src/mysql/mod.rs | 50 ++++++----- dump-parser/src/postgres/mod.rs | 60 ++++++------- dump-parser/src/utils.rs | 20 ++--- replibyte/src/commands/dump.rs | 32 +++---- replibyte/src/config.rs | 12 +-- replibyte/src/datastore/local_disk.rs | 30 +++---- replibyte/src/datastore/mod.rs | 6 +- replibyte/src/datastore/s3.rs | 30 +++---- replibyte/src/destination/docker.rs | 6 +- replibyte/src/destination/generic_stdout.rs | 7 +- replibyte/src/destination/mongodb.rs | 8 +- replibyte/src/destination/mongodb_docker.rs | 6 +- replibyte/src/destination/mysql.rs | 4 +- replibyte/src/destination/mysql_docker.rs | 6 +- replibyte/src/destination/postgres.rs | 4 +- replibyte/src/destination/postgres_docker.rs | 6 +- replibyte/src/main.rs | 10 +-- replibyte/src/migration/mod.rs | 4 +- .../src/migration/rename_backups_to_dumps.rs | 2 +- .../src/migration/update_version_number.rs | 2 +- replibyte/src/source/mongodb.rs | 26 +++--- replibyte/src/source/mongodb_stdin.rs | 9 +- replibyte/src/source/mysql.rs | 52 +++++------ replibyte/src/source/mysql_stdin.rs | 7 +- replibyte/src/source/postgres.rs | 86 +++++++++---------- replibyte/src/source/postgres_stdin.rs | 7 +- replibyte/src/tasks/full_dump.rs | 8 +- replibyte/src/tasks/full_restore.rs | 8 +- replibyte/src/telemetry.rs | 6 +- replibyte/src/transformer/credit_card.rs | 11 +-- replibyte/src/transformer/email.rs | 11 +-- replibyte/src/transformer/first_name.rs | 13 +-- replibyte/src/transformer/keep_first_char.rs | 13 +-- replibyte/src/transformer/mod.rs | 18 ++-- replibyte/src/transformer/phone_number.rs | 11 +-- replibyte/src/transformer/random.rs | 11 +-- replibyte/src/transformer/redacted.rs | 12 +-- replibyte/src/transformer/transient.rs | 11 +-- replibyte/src/utils.rs | 12 +-- subset/src/dedup.rs | 2 +- subset/src/lib.rs | 3 +- subset/src/postgres.rs | 54 ++++++------ 43 files changed, 312 insertions(+), 386 deletions(-) diff --git a/dump-parser/src/mongodb/mod.rs b/dump-parser/src/mongodb/mod.rs index 36796ff7..5087539b 100644 --- a/dump-parser/src/mongodb/mod.rs +++ b/dump-parser/src/mongodb/mod.rs @@ -120,7 +120,7 @@ impl Archive { // read metadata headers and seperator (seperator is read when while let fails for the 1st time) while let Ok(collection_metadata_doc) = bson::from_reader(&mut reader) { - let metadata_doc = Metadata::from(collection_metadata_doc); + let metadata_doc = collection_metadata_doc; metadata_docs.push(metadata_doc); num_blocks += 1; } diff --git a/dump-parser/src/mysql/mod.rs b/dump-parser/src/mysql/mod.rs index 059b5093..cd9c31f9 100644 --- a/dump-parser/src/mysql/mod.rs +++ b/dump-parser/src/mysql/mod.rs @@ -119,7 +119,7 @@ impl Token { Token::Word(Word { value: word.to_string(), quote_style, - keyword: if quote_style == None { + keyword: if quote_style.is_none() { match word_uppercase.as_str() { "ALTER" => Alter, "CREATE" => Create, @@ -303,7 +303,7 @@ impl<'a> Tokenizer<'a> { chars.next(); // consume the first char let s = self.tokenize_word(ch, chars); - if s.chars().all(|x| ('0'..='9').contains(&x) || x == '.') { + if s.chars().all(|x| x.is_ascii_digit() || x == '.') { let mut s = peeking_take_while(&mut s.chars().peekable(), |ch| { matches!(ch, '0'..='9' | '.') }); @@ -471,7 +471,7 @@ impl<'a> Tokenizer<'a> { /// Tokenize an identifier or keyword, after the first char is already consumed. fn tokenize_word(&self, first_char: char, chars: &mut Peekable>) -> String { let mut s = first_char.to_string(); - s.push_str(&peeking_take_while(chars, |ch| is_identifier_part(ch))); + s.push_str(&peeking_take_while(chars, is_identifier_part)); s } @@ -517,10 +517,10 @@ impl<'a> Tokenizer<'a> { ) -> Result, TokenizerError> { let mut s = match sign { Some(ch) if ch == '+' || ch == '-' => { - String::from(ch) + &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')) + String::from(ch) + &peeking_take_while(chars, |ch| ch.is_ascii_digit()) } Some(_) => panic!("invalid sign"), - None => peeking_take_while(chars, |ch| matches!(ch, '0'..='9')) + None => peeking_take_while(chars, |ch| ch.is_ascii_digit()) }; // match binary literal that starts with 0x @@ -538,7 +538,7 @@ impl<'a> Tokenizer<'a> { s.push('.'); chars.next(); } - s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + s += &peeking_take_while(chars, |ch| ch.is_ascii_digit()); // No number -> Token::Period if s == "." { @@ -596,13 +596,13 @@ fn is_identifier_start(ch: char) -> bool { // See https://www.postgresql.org/docs/14/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS // We don't yet support identifiers beginning with "letters with // diacritical marks and non-Latin letters" - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' } fn is_identifier_part(ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '$' || ch == '_' } @@ -661,7 +661,7 @@ pub fn get_single_quoted_string_value_at_position(tokens: &Vec, pos: usiz } pub fn get_column_names_from_create_query(tokens: &Vec) -> Vec { - if !match_keyword_at_position(Create, &tokens, 0) { + if !match_keyword_at_position(Create, tokens, 0) { return Vec::new(); } @@ -695,8 +695,8 @@ pub fn get_column_names_from_create_query(tokens: &Vec) -> Vec { } pub fn get_column_names_from_insert_into_query(tokens: &Vec) -> Vec<&str> { - if !match_keyword_at_position(Keyword::Insert, &tokens, 0) - || !match_keyword_at_position(Keyword::Into, &tokens, 2) + if !match_keyword_at_position(Keyword::Insert, tokens, 0) + || !match_keyword_at_position(Keyword::Into, tokens, 2) { // it means that the query is not an INSERT INTO.. one return Vec::new(); @@ -721,8 +721,8 @@ pub fn get_column_names_from_insert_into_query(tokens: &Vec) -> Vec<&str> } pub fn get_column_values_from_insert_into_query(tokens: &Vec) -> Vec<&Token> { - if !match_keyword_at_position(Keyword::Insert, &tokens, 0) - || !match_keyword_at_position(Keyword::Into, &tokens, 2) + if !match_keyword_at_position(Keyword::Insert, tokens, 0) + || !match_keyword_at_position(Keyword::Into, tokens, 2) { // it means that the query is not an INSERT INTO.. one return Vec::new(); @@ -987,7 +987,7 @@ VALUES (1,'Stanford','Stiedemann','alaina.moore@example.net','EUR',1,'2022-04-13 let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_names = get_column_names_from_insert_into_query(&tokens); @@ -1013,7 +1013,7 @@ VALUES (1,'Stanford','Stiedemann','alaina.moore@example.net','EUR',1,'2022-04-13 let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = tokens_result.unwrap(); let tokens = trim_pre_whitespaces(tokens); @@ -1043,14 +1043,12 @@ VALUES (1,'Stanford','Stiedemann','alaina.moore@example.net','EUR',1,NULL,'2022- "; let tokens = get_tokens_from_query_str(q); - assert_eq!( - match_keyword_at_position(super::Keyword::Insert, &tokens, 0), - true + assert!( + match_keyword_at_position(super::Keyword::Insert, &tokens, 0) ); - assert_eq!( - match_keyword_at_position(super::Keyword::Into, &tokens, 2), - true + assert!( + match_keyword_at_position(super::Keyword::Into, &tokens, 2) ); } @@ -1063,7 +1061,7 @@ VALUES ('Romaric', true); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_values = get_column_values_from_insert_into_query(&tokens); @@ -1086,7 +1084,7 @@ VALUES ('Romaric', true); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); assert_eq!( @@ -1102,7 +1100,7 @@ VALUES ('Romaric', true); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_values = get_column_values_from_insert_into_query(&tokens); diff --git a/dump-parser/src/postgres/mod.rs b/dump-parser/src/postgres/mod.rs index 30a8e1d6..68467416 100644 --- a/dump-parser/src/postgres/mod.rs +++ b/dump-parser/src/postgres/mod.rs @@ -123,7 +123,7 @@ impl Token { Token::Word(Word { value: word.to_string(), quote_style, - keyword: if quote_style == None { + keyword: if quote_style.is_none() { match word_uppercase.as_str() { "ALTER" => Alter, "CREATE" => Create, @@ -313,7 +313,7 @@ impl<'a> Tokenizer<'a> { chars.next(); // consume the first char let s = self.tokenize_word(ch, chars); - if s.chars().all(|x| ('0'..='9').contains(&x) || x == '.') { + if s.chars().all(|x| x.is_ascii_digit() || x == '.') { let mut s = peeking_take_while(&mut s.chars().peekable(), |ch| { matches!(ch, '0'..='9' | '.') }); @@ -496,7 +496,7 @@ impl<'a> Tokenizer<'a> { /// Tokenize an identifier or keyword, after the first char is already consumed. fn tokenize_word(&self, first_char: char, chars: &mut Peekable>) -> String { let mut s = first_char.to_string(); - s.push_str(&peeking_take_while(chars, |ch| is_identifier_part(ch))); + s.push_str(&peeking_take_while(chars, is_identifier_part)); s } @@ -544,10 +544,10 @@ impl<'a> Tokenizer<'a> { ) -> Result, TokenizerError> { let mut s = match sign { Some(ch) if ch == '+' || ch == '-' => { - String::from(ch) + &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')) + String::from(ch) + &peeking_take_while(chars, |ch| ch.is_ascii_digit()) } Some(_) => panic!("invalid sign"), - None => peeking_take_while(chars, |ch| matches!(ch, '0'..='9')) + None => peeking_take_while(chars, |ch| ch.is_ascii_digit()) }; // match binary literal that starts with 0x @@ -565,7 +565,7 @@ impl<'a> Tokenizer<'a> { s.push('.'); chars.next(); } - s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + s += &peeking_take_while(chars, |ch| ch.is_ascii_digit()); // No number -> Token::Period if s == "." { @@ -623,13 +623,13 @@ fn is_identifier_start(ch: char) -> bool { // See https://www.postgresql.org/docs/14/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS // We don't yet support identifiers beginning with "letters with // diacritical marks and non-Latin letters" - ('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' || ch == '"' + ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '"' } fn is_identifier_part(ch: char) -> bool { - ('a'..='z').contains(&ch) - || ('A'..='Z').contains(&ch) - || ('0'..='9').contains(&ch) + ch.is_ascii_lowercase() + || ch.is_ascii_uppercase() + || ch.is_ascii_digit() || ch == '$' || ch == '_' || ch == '"' @@ -698,8 +698,8 @@ pub fn get_word_value_at_position(tokens: &Vec, pos: usize) -> Option<&st } pub fn get_column_names_from_insert_into_query(tokens: &Vec) -> Vec { - if !match_keyword_at_position(Keyword::Insert, &tokens, 0) - || !match_keyword_at_position(Keyword::Into, &tokens, 2) + if !match_keyword_at_position(Keyword::Insert, tokens, 0) + || !match_keyword_at_position(Keyword::Into, tokens, 2) { // it means that the query is not an INSERT INTO.. one return Vec::new(); @@ -732,8 +732,8 @@ pub fn get_column_names_from_insert_into_query(tokens: &Vec) -> Vec) -> Vec<&Token> { - if !match_keyword_at_position(Keyword::Insert, &tokens, 0) - || !match_keyword_at_position(Keyword::Into, &tokens, 2) + if !match_keyword_at_position(Keyword::Insert, tokens, 0) + || !match_keyword_at_position(Keyword::Into, tokens, 2) { // it means that the query is not an INSERT INTO.. one return Vec::new(); @@ -761,7 +761,7 @@ pub fn get_column_values_from_insert_into_query(tokens: &Vec) -> Vec<&Tok } pub fn get_column_values_str_from_insert_into_query(tokens: &Vec) -> Vec { - get_column_values_from_insert_into_query(&tokens) + get_column_values_from_insert_into_query(tokens) .iter() .filter_map(|x| match *x { Token::Word(word) => Some(word.value.clone()), @@ -780,7 +780,7 @@ pub fn get_column_values_str_from_insert_into_query(tokens: &Vec) -> Vec< } pub fn get_column_names_from_create_query(tokens: &Vec) -> Vec { - if !match_keyword_at_position(Create, &tokens, 0) { + if !match_keyword_at_position(Create, tokens, 0) { return Vec::new(); } @@ -855,7 +855,7 @@ CREATE TABLE public.orders ( let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = tokens_result.unwrap(); @@ -917,11 +917,11 @@ CREATE TABLE public.application ( let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); - let tokens = tokens_result.unwrap(); + let _tokens = tokens_result.unwrap(); - let expected: Vec = vec![]; + let _expected: Vec = vec![]; // FIXME assert_eq!(tokens, expected); } @@ -942,11 +942,11 @@ COPY public.categories (category_id, category_name, description, picture) FROM s let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); - let tokens = tokens_result.unwrap(); + let _tokens = tokens_result.unwrap(); - let expected: Vec = vec![]; + let _expected: Vec = vec![]; // FIXME assert_eq!(tokens, expected); } @@ -960,11 +960,11 @@ VALUES (1, 'Alfreds Futterkiste', 'Maria Anders', NULL); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); - let tokens = tokens_result.unwrap(); + let _tokens = tokens_result.unwrap(); - let expected: Vec = vec![]; + let _expected: Vec = vec![]; // FIXME assert_eq!(tokens, expected); } @@ -977,7 +977,7 @@ VALUES (1, 'Alfreds Futterkiste', 'Maria Anders', NULL, NULL); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_names = get_column_names_from_insert_into_query(&tokens); @@ -1003,7 +1003,7 @@ VALUES (1, 'Alfreds Futterkiste', 'Maria Anders', NULL); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_values = get_column_values_from_insert_into_query(&tokens); @@ -1028,7 +1028,7 @@ VALUES ('Romaric', true); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_values = get_column_values_from_insert_into_query(&tokens); @@ -1048,7 +1048,7 @@ VALUES ('Romaric', true); let mut tokenizer = Tokenizer::new(q); let tokens_result = tokenizer.tokenize(); - assert_eq!(tokens_result.is_ok(), true); + assert!(tokens_result.is_ok()); let tokens = trim_pre_whitespaces(tokens_result.unwrap()); let column_values = get_column_values_from_insert_into_query(&tokens); diff --git a/dump-parser/src/utils.rs b/dump-parser/src/utils.rs index c5bdc505..ed1ea7ae 100644 --- a/dump-parser/src/utils.rs +++ b/dump-parser/src/utils.rs @@ -63,7 +63,7 @@ where None => false, }; - let mut query_res = ListQueryResult::Continue; + let query_res = ListQueryResult::Continue; buf_bytes.append(&mut line_buf_bytes); @@ -73,7 +73,7 @@ where if buf_bytes.len() > 1 { let query_str = match str::from_utf8(buf_bytes.as_slice()) { Ok(t) => t, - Err(e) => continue + Err(_e) => continue }; for statement in list_statements(query_str) { @@ -97,7 +97,7 @@ where } } - let _ = buf_bytes.clear(); + buf_bytes.clear(); buf_bytes.extend_from_slice(buf_bytes_to_keep.as_slice()); count_empty_lines += 1; } else { @@ -187,7 +187,7 @@ fn list_statements(query: &str) -> Vec { previous_chars_are_whitespaces = true; } b'\'' if !is_comment_line && !is_partial_comment_line => { - if stack.get(0) == Some(&b'\'') { + if stack.first() == Some(&b'\'') { if (query.len() > next_idx) && &query[next_idx..next_idx] == "'" { // do nothing because the ' char is escaped via a double '' } else if idx > 0 && query.is_char_boundary(idx-1) && &query[idx-1..idx] == "\\" { @@ -204,7 +204,7 @@ fn list_statements(query: &str) -> Vec { } b'(' if !is_comment_line && !is_partial_comment_line - && stack.get(0) != Some(&b'\'') => + && stack.first() != Some(&b'\'') => { stack.insert(0, byte_char); is_statement_complete = false; @@ -212,9 +212,9 @@ fn list_statements(query: &str) -> Vec { previous_chars_are_whitespaces = false; } b')' if !is_comment_line && !is_partial_comment_line => { - if stack.get(0) == Some(&b'(') { + if stack.first() == Some(&b'(') { let _ = stack.remove(0); - } else if stack.get(0) != Some(&b'\'') { + } else if stack.first() != Some(&b'\'') { stack.insert(0, byte_char); } @@ -234,7 +234,7 @@ fn list_statements(query: &str) -> Vec { // use grapheme instead of code points or bytes? b'-' if !is_statement_complete && next_idx < query_bytes.len() && query_bytes[next_idx] == b'-' - && stack.get(0) != Some(&b'\'') => + && stack.first() != Some(&b'\'') => { // comment is_partial_comment_line = true; @@ -246,7 +246,7 @@ fn list_statements(query: &str) -> Vec { } b';' if !is_comment_line && !is_partial_comment_line - && stack.get(0) != Some(&b'\'') => + && stack.first() != Some(&b'\'') => { // end of query sql_statements.push(Statement::Query(QueryStatement { @@ -325,7 +325,7 @@ Etiam augue augue, bibendum et molestie non, finibus non nulla. Etiam quis rhonc ListQueryResult::Continue }); - assert!(queries.len() > 0); + assert!(!queries.is_empty()); } #[test] diff --git a/replibyte/src/commands/dump.rs b/replibyte/src/commands/dump.rs index 22eb765a..e101994e 100644 --- a/replibyte/src/commands/dump.rs +++ b/replibyte/src/commands/dump.rs @@ -72,7 +72,7 @@ pub fn run( progress_callback: F, ) -> anyhow::Result<()> where - F: Fn(usize, usize) -> (), + F: Fn(usize, usize), { if let Some(encryption_key) = config.encryption_key()? { datastore.set_encryption_key(encryption_key) @@ -129,12 +129,12 @@ where let options = SourceOptions { transformers: &transformers, - skip_config: &skip_config, + skip_config, database_subset: &source.database_subset, - only_tables: &only_tables_config, + only_tables: only_tables_config, }; - match args.source_type.as_ref().map(|x| x.as_str()) { + match args.source_type.as_deref() { None => match source.connection_uri()? { ConnectionUri::Postgres(host, port, username, password, database) => { let postgres = Postgres::new( @@ -216,16 +216,16 @@ where Ok(()) } None => { - return Err(anyhow::Error::from(Error::new( + Err(anyhow::Error::from(Error::new( ErrorKind::Other, "missing object in the configuration file", - ))); + ))) } } } pub fn delete(datastore: Box, args: &DumpDeleteArgs) -> anyhow::Result<()> { - let _ = datastore.delete(args)?; + datastore.delete(args)?; println!("Dump deleted!"); Ok(()) } @@ -238,7 +238,7 @@ pub fn restore_local( progress_callback: F, ) -> anyhow::Result<()> where - F: Fn(usize, usize) -> (), + F: Fn(usize, usize), { if let Some(encryption_key) = config.encryption_key()? { datastore.set_encryption_key(encryption_key); @@ -254,7 +254,7 @@ where if args.output { let mut generic_stdout = GenericStdout::new(); let task = FullRestoreTask::new(&mut generic_stdout, datastore, options); - let _ = task.run(|_, _| {})?; // do not display the progress bar + task.run(|_, _| {})?; // do not display the progress bar return Ok(()); } @@ -279,7 +279,7 @@ where let mut postgres = PostgresDocker::new(tag.to_string(), port); let task = FullRestoreTask::new(&mut postgres, datastore, options); - let _ = task.run(progress_callback)?; + task.run(progress_callback)?; print_connection_string_and_wait( "To connect to your PostgreSQL instance, use the following connection string:", @@ -327,7 +327,7 @@ where let mut mongodb = MongoDBDocker::new(tag.to_string(), port); let task = FullRestoreTask::new(&mut mongodb, datastore, options); - let _ = task.run(progress_callback)?; + task.run(progress_callback)?; print_connection_string_and_wait( "To connect to your MongoDB instance, use the following connection string:", @@ -372,7 +372,7 @@ where let mut mysql = MysqlDocker::new(tag.to_string(), port); let task = FullRestoreTask::new(&mut mysql, datastore, options); - let _ = task.run(progress_callback)?; + task.run(progress_callback)?; print_connection_string_and_wait( "To connect to your MySQL instance, use the following connection string:", @@ -419,7 +419,7 @@ pub fn restore_remote( progress_callback: F, ) -> anyhow::Result<()> where - F: Fn(usize, usize) -> (), + F: Fn(usize, usize), { if let Some(encryption_key) = config.encryption_key()? { datastore.set_encryption_key(encryption_key); @@ -435,7 +435,7 @@ where if args.output { let mut generic_stdout = GenericStdout::new(); let task = FullRestoreTask::new(&mut generic_stdout, datastore, options); - let _ = task.run(|_, _| {})?; // do not display the progress bar + task.run(|_, _| {})?; // do not display the progress bar return Ok(()); } @@ -479,10 +479,10 @@ where Ok(()) } None => { - return Err(anyhow::Error::from(Error::new( + Err(anyhow::Error::from(Error::new( ErrorKind::Other, "missing object in the configuration file", - ))); + ))) } } } diff --git a/replibyte/src/config.rs b/replibyte/src/config.rs index 547f12cc..d29fdb2e 100644 --- a/replibyte/src/config.rs +++ b/replibyte/src/config.rs @@ -9,7 +9,7 @@ use crate::transformer::redacted::{RedactedTransformer, RedactedTransformerOptio use crate::transformer::transient::TransientTransformer; use crate::transformer::Transformer; use percent_encoding::percent_decode_str; -use serde; + use serde::{Deserialize, Serialize}; use std::io::{Error, ErrorKind}; use url::Url; @@ -47,7 +47,7 @@ impl Config { pub fn encryption_key(&self) -> Result, Error> { match &self.encryption_key { - Some(key) => substitute_env_var(key.as_str()).map(|x| Some(x)), + Some(key) => substitute_env_var(key.as_str()).map(Some), None => Ok(None), } } @@ -212,7 +212,7 @@ impl SourceConfig { Some(connection_uri) => parse_connection_uri(connection_uri.as_str()), None => Err(Error::new( ErrorKind::Other, - format!("missing in the configuration file"), + "missing in the configuration file".to_string(), )), } } @@ -412,7 +412,7 @@ fn get_port(url: &Url, default_port: u16) -> Result { fn get_username(url: &Url) -> Result { match url.username() { - username if username != "" => Ok(percent_decode_str(&username) + username if !username.is_empty() => Ok(percent_decode_str(username) .decode_utf8_lossy() .to_string()), _ => Err(Error::new( @@ -431,7 +431,7 @@ fn get_password(url: &Url) -> Result { fn get_database(url: &Url, default: Option<&str>) -> Result { let path = url.path().to_string(); - let database = path.split("/").collect::>(); + let database = path.split('/').collect::>(); if database.is_empty() { return match default { @@ -511,7 +511,7 @@ pub enum Endpoint { fn substitute_env_var(env_var: &str) -> Result { match env_var { "" => Ok(String::new()), - env_var if env_var.starts_with("$") && env_var.len() > 1 => { + env_var if env_var.starts_with('$') && env_var.len() > 1 => { let key = &env_var[1..env_var.len()]; match std::env::var(key) { Ok(value) => Ok(value), diff --git a/replibyte/src/datastore/local_disk.rs b/replibyte/src/datastore/local_disk.rs index 6825c67c..cd554c1c 100644 --- a/replibyte/src/datastore/local_disk.rs +++ b/replibyte/src/datastore/local_disk.rs @@ -1,6 +1,6 @@ use std::fs::{read, read_dir, remove_dir_all, write, DirBuilder, OpenOptions}; use std::io::{BufReader, Error, Read, Write}; -use std::path::Path; + use log::{debug, error, info}; use serde_json::Value; @@ -34,7 +34,7 @@ impl LocalDisk { Err(_) => { info!("creating a new index_file"); let index_file = IndexFile::new(); - let _ = self.write_index_file(&index_file)?; + self.write_index_file(&index_file)?; Ok(index_file) } } @@ -59,7 +59,7 @@ impl Datastore for LocalDisk { let reader = BufReader::new(file); let index_file: IndexFile = - serde_json::from_reader(reader).map_err(|err| Error::from(err))?; + serde_json::from_reader(reader).map_err(Error::from)?; Ok(index_file) } @@ -73,7 +73,7 @@ impl Datastore for LocalDisk { let reader = BufReader::new(file); - let raw_index_file = serde_json::from_reader(reader).map_err(|err| Error::from(err))?; + let raw_index_file = serde_json::from_reader(reader).map_err(Error::from)?; Ok(raw_index_file) } @@ -90,7 +90,7 @@ impl Datastore for LocalDisk { .open(&index_file_path)?; debug!("writing index_file at {}", index_file_path.as_str()); - serde_json::to_writer(file, index_file).map_err(|err| Error::from(err)) + serde_json::to_writer(file, index_file).map_err(Error::from) } fn write_raw_index_file(&self, raw_index_file: &Value) -> Result<(), Error> { @@ -105,7 +105,7 @@ impl Datastore for LocalDisk { .open(&index_file_path)?; debug!("writing raw index_file at {}", index_file_path.as_str()); - serde_json::to_writer(file, raw_index_file).map_err(|err| Error::from(err)) + serde_json::to_writer(file, raw_index_file).map_err(Error::from) } fn write(&self, file_part: u16, data: types::Bytes) -> Result<(), Error> { @@ -136,7 +136,7 @@ impl Datastore for LocalDisk { })?; debug!("writing dump at: {}", dump_file_path); - let _ = write(&dump_file_path, data).map_err(|err| { + write(&dump_file_path, data).map_err(|err| { error!("error while writing dumpt at: {}", dump_file_path); err })?; @@ -166,7 +166,7 @@ impl Datastore for LocalDisk { index_file.dumps.push(new_dump); } else { // update total dump size - dump.size = dump.size + data_size; + dump.size += data_size; } // save index file @@ -300,7 +300,7 @@ mod tests { fn test_write_and_read() { let dir = tempdir().expect("cannot create tempdir"); let mut local_disk = LocalDisk::new(dir.path().to_str().unwrap().to_string()); - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); let bytes: Vec = b"hello world".to_vec(); @@ -334,7 +334,7 @@ mod tests { fn test_index_file() { let dir = tempdir().expect("cannot create tempdir"); let mut local_disk = LocalDisk::new(dir.path().to_str().unwrap().to_string()); - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); assert!(local_disk.index_file().is_ok()); @@ -371,7 +371,7 @@ mod tests { let mut local_disk = LocalDisk::new(dir.path().to_str().unwrap().to_string()); // init local_disk - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); assert!(local_disk.index_file().is_ok()); let index_file = local_disk.index_file().unwrap(); assert!(index_file.dumps.is_empty()); @@ -419,7 +419,7 @@ mod tests { let mut local_disk = LocalDisk::new(dir.path().to_str().unwrap().to_string()); // init local_disk - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); assert!(local_disk.index_file().is_ok()); let index_file = local_disk.index_file().unwrap(); assert!(index_file.dumps.is_empty()); @@ -481,7 +481,7 @@ mod tests { let mut local_disk = LocalDisk::new(dir.path().to_str().unwrap().to_string()); // init local_disk - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); assert!(local_disk.index_file().is_ok()); let index_file = local_disk.index_file().unwrap(); assert!(index_file.dumps.is_empty()); @@ -568,7 +568,7 @@ mod tests { .create(true) .write(true) .truncate(true) - .open(&format!( + .open(format!( "{}/{}", dir.path().to_str().unwrap(), INDEX_FILE_NAME @@ -610,7 +610,7 @@ mod tests { ); assert!(migrator.migrate().is_ok()); - let _ = local_disk.init().expect("local_disk init failed"); + local_disk.init().expect("local_disk init failed"); // assert assert!(local_disk.index_file().is_ok()); diff --git a/replibyte/src/datastore/mod.rs b/replibyte/src/datastore/mod.rs index a846423a..17cbd0ad 100644 --- a/replibyte/src/datastore/mod.rs +++ b/replibyte/src/datastore/mod.rs @@ -138,7 +138,7 @@ impl IndexFile { match self.dumps.last() { Some(dump) => Ok(dump), - None => return Err(Error::new(ErrorKind::Other, "No dumps available.")), + None => Err(Error::new(ErrorKind::Other, "No dumps available.")), } } ReadOptions::Dump { name } => { @@ -149,10 +149,10 @@ impl IndexFile { { Some(dump) => Ok(dump), None => { - return Err(Error::new( + Err(Error::new( ErrorKind::Other, format!("Can't find dump with name '{}'", name), - )); + )) } } } diff --git a/replibyte/src/datastore/s3.rs b/replibyte/src/datastore/s3.rs index 5ab348fb..f922cedb 100644 --- a/replibyte/src/datastore/s3.rs +++ b/replibyte/src/datastore/s3.rs @@ -150,7 +150,7 @@ impl S3 { Ok(index_file) => Ok(index_file), Err(_) => { let index_file = IndexFile::new(); - let _ = self.write_index_file(&index_file)?; + self.write_index_file(&index_file)?; Ok(index_file) } } @@ -164,7 +164,7 @@ impl Connector for S3 { // Do not try to create bucket - the current S3 client does not supports well GCP Cloud Storage } _ => { - let _ = create_bucket(&self.client, self.bucket.as_str(), self.region.as_ref())?; + create_bucket(&self.client, self.bucket.as_str(), self.region.as_ref())?; } } @@ -195,7 +195,7 @@ impl Datastore for S3 { INDEX_FILE_NAME, index_file_json, ) - .map_err(|err| Error::from(err)) + .map_err(Error::from) } fn write_raw_index_file(&self, raw_index_file: &Value) -> Result<(), Error> { @@ -207,7 +207,7 @@ impl Datastore for S3 { INDEX_FILE_NAME, index_file_json, ) - .map_err(|err| Error::from(err)) + .map_err(Error::from) } fn write(&self, file_part: u16, data: Bytes) -> Result<(), Error> { @@ -224,7 +224,7 @@ impl Datastore for S3 { fn read( &self, options: &ReadOptions, - mut data_callback: &mut dyn FnMut(Bytes), + data_callback: &mut dyn FnMut(Bytes), ) -> Result<(), Error> { let mut index_file = self.index_file()?; let dump = index_file.find_dump(options)?; @@ -284,7 +284,7 @@ impl Datastore for S3 { let bucket = &self.bucket; - let _ = delete_directory(&self.client, bucket, &name).map_err(|err| Error::from(err))?; + delete_directory(&self.client, bucket, &name).map_err(Error::from)?; index_file.dumps.retain(|b| b.directory_name != name); @@ -318,7 +318,7 @@ fn write_objects( info!("upload object '{}' part {} on", key.as_str(), file_part); - let _ = create_object(client, bucket, key.as_str(), data)?; + create_object(client, bucket, key.as_str(), data)?; // update index file let mut index_file = datastore.index_file()?; @@ -345,7 +345,7 @@ fn write_objects( index_file.dumps.push(new_dump); } else { // update total dump size - dump.size = dump.size + data_size; + dump.size += data_size; } // save index file @@ -704,7 +704,7 @@ mod tests { let bucket = aws_bucket(); let mut s3 = aws_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); let key = format!("testing-object-{}", Faker.fake::()); @@ -774,7 +774,7 @@ mod tests { fn create_and_get_and_delete_object_for_gcp_s3() { let bucket = gcp_bucket(); let mut s3 = gcp_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); let key = format!("testing-object-{}", Faker.fake::()); @@ -843,7 +843,7 @@ mod tests { let bucket = aws_bucket(); let mut s3 = aws_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); assert!(s3.index_file().is_ok()); @@ -881,7 +881,7 @@ mod tests { let bucket = aws_bucket(); let mut s3 = aws_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); assert!(s3.index_file().is_ok()); @@ -953,7 +953,7 @@ mod tests { let bucket = aws_bucket(); let mut s3 = aws_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); assert!(s3.index_file().is_ok()); @@ -1028,7 +1028,7 @@ mod tests { let bucket = aws_bucket(); let mut s3 = aws_s3(bucket.as_str()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); assert!(s3.index_file().is_ok()); @@ -1162,7 +1162,7 @@ mod tests { ); assert!(migrator.migrate().is_ok()); - let _ = s3.init().expect("s3 init failed"); + s3.init().expect("s3 init failed"); // assert assert!(s3.index_file().is_ok()); diff --git a/replibyte/src/destination/docker.rs b/replibyte/src/destination/docker.rs index b69e0a23..98be261d 100644 --- a/replibyte/src/destination/docker.rs +++ b/replibyte/src/destination/docker.rs @@ -54,7 +54,7 @@ impl Container { Err(err) => Err(Error::new(ErrorKind::Other, format!("{}", err))), }, false => match String::from_utf8(output.stderr) { - Ok(stderr) => Err(Error::new(ErrorKind::Other, format!("{}", stderr))), + Ok(stderr) => Err(Error::new(ErrorKind::Other, stderr)), Err(err) => Err(Error::new(ErrorKind::Other, format!("{}", err))), }, } @@ -106,7 +106,7 @@ pub fn daemon_is_running() -> Result<(), Error> { ErrorKind::Other, format!( "cannot connect to the Docker daemon: exit_status {}", - exit_status.to_string() + exit_status ), )) } @@ -143,7 +143,7 @@ mod tests { let container = Container::new(&image, &options, args, None).unwrap(); - assert!(container.id != "".to_string()); + assert!(container.id != *""); assert!(container.stop().is_ok()); assert!(container.rm().is_ok()); } diff --git a/replibyte/src/destination/generic_stdout.rs b/replibyte/src/destination/generic_stdout.rs index 4263f45c..12cecc11 100644 --- a/replibyte/src/destination/generic_stdout.rs +++ b/replibyte/src/destination/generic_stdout.rs @@ -5,6 +5,7 @@ use crate::destination::Destination; use crate::types::Bytes; /// Stream dump output on stdout +#[derive(Default)] pub struct GenericStdout {} impl GenericStdout { @@ -13,11 +14,7 @@ impl GenericStdout { } } -impl Default for GenericStdout { - fn default() -> Self { - GenericStdout {} - } -} + impl Connector for GenericStdout { fn init(&mut self) -> Result<(), Error> { diff --git a/replibyte/src/destination/mongodb.rs b/replibyte/src/destination/mongodb.rs index d2a821fe..787a610f 100644 --- a/replibyte/src/destination/mongodb.rs +++ b/replibyte/src/destination/mongodb.rs @@ -19,9 +19,9 @@ impl<'a> MongoDB<'a> { impl<'a> Connector for MongoDB<'a> { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists("mongosh")?; - let _ = binary_exists("mongorestore")?; - let _ = check_connection_status(self)?; + binary_exists("mongosh")?; + binary_exists("mongorestore")?; + check_connection_status(self)?; Ok(()) } @@ -85,7 +85,7 @@ mod tests { #[test] fn connect() { let mut p = get_mongodb(); - let _ = p.init().expect("can't init mongodb"); + p.init().expect("can't init mongodb"); let bytes = decode_hex("6de299816600000010636f6e63757272656e745f636f6c6c656374696f6e7300040000000276657273696f6e0004000000302e3100027365727665725f76657273696f6e0006000000352e302e360002746f6f6c5f76657273696f6e00080000003130302e352e320000020100000264620005000000746573740002636f6c6c656374696f6e0006000000757365727300026d6574616461746100ad0000007b22696e6465786573223a5b7b2276223a7b22246e756d626572496e74223a2232227d2c226b6579223a7b225f6964223a7b22246e756d626572496e74223a2231227d7d2c226e616d65223a225f69645f227d5d2c2275756964223a223464363734323637316333613463663938316439386164373831343735333234222c22636f6c6c656374696f6e4e616d65223a227573657273222c2274797065223a22636f6c6c656374696f6e227d001073697a6500000000000274797065000b000000636f6c6c656374696f6e0000ffffffff3b0000000264620005000000746573740002636f6c6c656374696f6e000600000075736572730008454f4600001243524300000000000000000000ffffffff3b0000000264620005000000746573740002636f6c6c656374696f6e000600000075736572730008454f4600011243524300000000000000000000ffffffff00").unwrap(); assert!(p.write(bytes.to_vec()).is_ok()); diff --git a/replibyte/src/destination/mongodb_docker.rs b/replibyte/src/destination/mongodb_docker.rs index 94a2f86b..b211afe2 100644 --- a/replibyte/src/destination/mongodb_docker.rs +++ b/replibyte/src/destination/mongodb_docker.rs @@ -37,8 +37,8 @@ impl MongoDBDocker { impl Connector for MongoDBDocker { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists(DOCKER_BINARY_NAME)?; - let _ = daemon_is_running()?; + binary_exists(DOCKER_BINARY_NAME)?; + daemon_is_running()?; let password_env = format!("MONGO_INITDB_ROOT_USERNAME={}", DEFAULT_MONGO_USER); let user_env = format!("MONGO_INITDB_ROOT_PASSWORD={}", DEFAULT_MONGO_PASSWORD); @@ -107,7 +107,7 @@ mod tests { #[test] fn connect() { let mut p = get_mongodb(); - let _ = p.init().expect("can't init mongodb"); + p.init().expect("can't init mongodb"); let bytes = decode_hex("6de299816600000010636f6e63757272656e745f636f6c6c656374696f6e7300040000000276657273696f6e0004000000302e3100027365727665725f76657273696f6e0006000000352e302e360002746f6f6c5f76657273696f6e00080000003130302e352e320000020100000264620005000000746573740002636f6c6c656374696f6e0006000000757365727300026d6574616461746100ad0000007b22696e6465786573223a5b7b2276223a7b22246e756d626572496e74223a2232227d2c226b6579223a7b225f6964223a7b22246e756d626572496e74223a2231227d7d2c226e616d65223a225f69645f227d5d2c2275756964223a223464363734323637316333613463663938316439386164373831343735333234222c22636f6c6c656374696f6e4e616d65223a227573657273222c2274797065223a22636f6c6c656374696f6e227d001073697a6500000000000274797065000b000000636f6c6c656374696f6e0000ffffffff3b0000000264620005000000746573740002636f6c6c656374696f6e000600000075736572730008454f4600001243524300000000000000000000ffffffff3b0000000264620005000000746573740002636f6c6c656374696f6e000600000075736572730008454f4600011243524300000000000000000000ffffffff00").unwrap(); assert!(p.write(bytes.to_vec()).is_ok()); diff --git a/replibyte/src/destination/mysql.rs b/replibyte/src/destination/mysql.rs index a5c54fc7..cd9ad870 100644 --- a/replibyte/src/destination/mysql.rs +++ b/replibyte/src/destination/mysql.rs @@ -34,7 +34,7 @@ impl<'a> Mysql<'a> { impl<'a> Connector for Mysql<'a> { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists("mysql")?; + binary_exists("mysql")?; // test MySQL connection let mut process = Command::new("mysql") @@ -96,7 +96,7 @@ mod tests { #[test] fn connect() { let mut m = get_mysql(); - let _ = m.init().expect("can't init mysql"); + m.init().expect("can't init mysql"); assert!(m.write(b"SELECT 1;".to_vec()).is_ok()); let mut m = get_invalid_mysql(); diff --git a/replibyte/src/destination/mysql_docker.rs b/replibyte/src/destination/mysql_docker.rs index 8acfd30e..7b1fcaee 100644 --- a/replibyte/src/destination/mysql_docker.rs +++ b/replibyte/src/destination/mysql_docker.rs @@ -36,8 +36,8 @@ impl MysqlDocker { impl Connector for MysqlDocker { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists(DOCKER_BINARY_NAME)?; - let _ = daemon_is_running()?; + binary_exists(DOCKER_BINARY_NAME)?; + daemon_is_running()?; let password_env = format!("MYSQL_ROOT_PASSWORD={}", DEFAULT_MYSQL_PASSWORD); let container = Container::new( @@ -102,7 +102,7 @@ mod tests { #[test] fn connect() { let mut p = get_mysql(); - let _ = p.init().expect("can't init mysql"); + p.init().expect("can't init mysql"); assert!(p.write(b"SELECT 1".to_vec()).is_ok()); // cleanup container diff --git a/replibyte/src/destination/postgres.rs b/replibyte/src/destination/postgres.rs index ca549ec0..7f8452d2 100644 --- a/replibyte/src/destination/postgres.rs +++ b/replibyte/src/destination/postgres.rs @@ -37,7 +37,7 @@ impl<'a> Postgres<'a> { impl<'a> Connector for Postgres<'a> { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists("psql")?; + binary_exists("psql")?; if self.wipe_database { let s_port = self.port.to_string(); @@ -128,7 +128,7 @@ mod tests { #[test] fn connect() { let mut p = get_postgres(); - let _ = p.init().expect("can't init postgres"); + p.init().expect("can't init postgres"); assert!(p.write(b"SELECT 1".to_vec()).is_ok()); let mut p = get_invalid_postgres(); diff --git a/replibyte/src/destination/postgres_docker.rs b/replibyte/src/destination/postgres_docker.rs index e0b47120..e252b462 100644 --- a/replibyte/src/destination/postgres_docker.rs +++ b/replibyte/src/destination/postgres_docker.rs @@ -38,8 +38,8 @@ impl PostgresDocker { impl Connector for PostgresDocker { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists(DOCKER_BINARY_NAME)?; - let _ = daemon_is_running()?; + binary_exists(DOCKER_BINARY_NAME)?; + daemon_is_running()?; let password_env = format!("POSTGRES_PASSWORD={}", DEFAULT_POSTGRES_PASSWORD); let user_env = format!("POSTGRES_USER={}", DEFAULT_POSTGRES_USER); @@ -106,7 +106,7 @@ mod tests { #[test] fn connect() { let mut p = get_postgres(); - let _ = p.init().expect("can't init postgres"); + p.init().expect("can't init postgres"); assert!(p.write(b"SELECT 1".to_vec()).is_ok()); // cleanup container diff --git a/replibyte/src/main.rs b/replibyte/src/main.rs index 24d7b017..3d1ee28d 100644 --- a/replibyte/src/main.rs +++ b/replibyte/src/main.rs @@ -100,7 +100,7 @@ fn main() { } let mut exit_code = 0; - if let Err(err) = run(config, &sub_commands) { + if let Err(err) = run(config, sub_commands) { eprintln!("{}", err); exit_code = 1; } @@ -138,9 +138,9 @@ fn run(config: Config, sub_commands: &SubCommand) -> anyhow::Result<()> { }; let migrator = Migrator::new(get_replibyte_version(), &datastore, migrations()); - let _ = migrator.migrate()?; + migrator.migrate()?; - let _ = datastore.init()?; + datastore.init()?; let (tx_pb, rx_pb) = mpsc::sync_channel::<(TransferredBytes, MaxBytes)>(1000); @@ -167,7 +167,7 @@ fn run(config: Config, sub_commands: &SubCommand) -> anyhow::Result<()> { match sub_commands { SubCommand::Dump(cmd) => match cmd { DumpCommand::List => { - let _ = commands::dump::list(&mut datastore)?; + commands::dump::list(&mut datastore)?; Ok(()) } DumpCommand::Create(args) => { @@ -194,7 +194,7 @@ fn run(config: Config, sub_commands: &SubCommand) -> anyhow::Result<()> { }, SubCommand::Transformer(cmd) => match cmd { TransformerCommand::List => { - let _ = commands::transformer::list(); + commands::transformer::list(); Ok(()) } }, diff --git a/replibyte/src/migration/mod.rs b/replibyte/src/migration/mod.rs index f201d466..2f3ee692 100644 --- a/replibyte/src/migration/mod.rs +++ b/replibyte/src/migration/mod.rs @@ -27,7 +27,7 @@ impl FromStr for Version { match numbers.len() { 3 => { // unwrap is safe here as we know we have 3 items in vec. - let major = parse_str_to_u8(numbers.get(0).unwrap())?; + let major = parse_str_to_u8(numbers.first().unwrap())?; let minor = parse_str_to_u8(numbers.get(1).unwrap())?; let patch = parse_str_to_u8(numbers.get(2).unwrap())?; @@ -85,7 +85,7 @@ impl<'a> Migrator<'a> { Ok(_) => { for migration in &self.migrations { if self.should_run_migration(migration) { - let _ = migration.run(&self.datastore)?; + migration.run(self.datastore)?; } } Ok(()) diff --git a/replibyte/src/migration/rename_backups_to_dumps.rs b/replibyte/src/migration/rename_backups_to_dumps.rs index 9c54e796..6bbb44f0 100644 --- a/replibyte/src/migration/rename_backups_to_dumps.rs +++ b/replibyte/src/migration/rename_backups_to_dumps.rs @@ -27,7 +27,7 @@ impl Migration for RenameBackupsToDump { info!("migrate: rename backups to dumps"); let mut raw_index_file = datastore.raw_index_file()?; - let _ = rename_backups_to_dumps(&mut raw_index_file)?; + rename_backups_to_dumps(&mut raw_index_file)?; datastore.write_raw_index_file(&raw_index_file) } } diff --git a/replibyte/src/migration/update_version_number.rs b/replibyte/src/migration/update_version_number.rs index fa4e5f48..91c333f0 100644 --- a/replibyte/src/migration/update_version_number.rs +++ b/replibyte/src/migration/update_version_number.rs @@ -29,7 +29,7 @@ impl<'a> Migration for UpdateVersionNumber<'a> { info!("migrate: update version number"); let mut raw_index_file = datastore.raw_index_file()?; - let _ = update_version(&mut raw_index_file, self.version)?; + update_version(&mut raw_index_file, self.version)?; datastore.write_raw_index_file(&raw_index_file) } } diff --git a/replibyte/src/source/mongodb.rs b/replibyte/src/source/mongodb.rs index 5857febd..85f95a5d 100644 --- a/replibyte/src/source/mongodb.rs +++ b/replibyte/src/source/mongodb.rs @@ -26,9 +26,9 @@ impl<'a> MongoDB<'a> { impl<'a> Connector for MongoDB<'a> { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists("mongosh")?; - let _ = binary_exists("mongodump")?; - let _ = check_connection_status(self)?; + binary_exists("mongosh")?; + binary_exists("mongodump")?; + check_connection_status(self)?; Ok(()) } @@ -133,7 +133,7 @@ pub fn recursively_transform_bson( let mut column; match bson { Bson::String(value) => { - column = Column::StringValue(key.clone(), value.clone()); + column = Column::StringValue(key.clone(), value); column = match transformers.get(key.as_str()) { Some(transformer) => transformer.transform(column), // apply transformation on the column None => column, @@ -245,7 +245,7 @@ pub(crate) fn find_all_keys_with_array_wildcard_op( } // try to find last delim let last_delim = ".$[]"; // no dot at the end - if let Some(_) = column_name[iter..].find(last_delim) { + if column_name[iter..].contains(last_delim) { let key = column_name.to_string(); wildcard_keys.insert(format!("{}.{}", transformer.database_and_table_name(), key)); } @@ -361,7 +361,7 @@ mod tests { fn connect() { let p = get_mongodb(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -373,7 +373,7 @@ mod tests { assert!(p.read(source_options, |_, _| {}).is_ok()); let p = get_invalid_mongodb(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -388,7 +388,7 @@ mod tests { #[test] fn list_rows() { let p = get_mongodb(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -398,8 +398,8 @@ mod tests { }; p.read(source_options, |original_query, query| { - assert!(original_query.data().len() > 0); - assert!(query.data().len() > 0); + assert!(!original_query.data().is_empty()); + assert!(!query.data().is_empty()); }) .unwrap(); } @@ -413,7 +413,7 @@ mod tests { "no_nest": 5, "info": { "ext": { - "number": 123456789000 as i64 + "number": 123456789000_i64 } }, "info_arr" : [ @@ -426,7 +426,7 @@ mod tests { let t: Box = Box::new(RandomTransformer::new( database_name, table_name, - &c.to_string(), + c, )); t })); @@ -498,7 +498,7 @@ mod tests { let t: Box = Box::new(RandomTransformer::new( database_name, table_name, - column_name.into(), + column_name, )); let transformers_vec = vec![t]; // create a set of wildcards to be used in the transformation diff --git a/replibyte/src/source/mongodb_stdin.rs b/replibyte/src/source/mongodb_stdin.rs index 8c39cbbb..923d272e 100644 --- a/replibyte/src/source/mongodb_stdin.rs +++ b/replibyte/src/source/mongodb_stdin.rs @@ -6,13 +6,10 @@ use crate::types::{OriginalQuery, Query}; use crate::Source; use crate::SourceOptions; +#[derive(Default)] pub struct MongoDBStdin {} -impl Default for MongoDBStdin { - fn default() -> Self { - Self {} - } -} + impl Connector for MongoDBStdin { fn init(&mut self) -> Result<(), Error> { @@ -32,7 +29,7 @@ impl Source for MongoDBStdin { todo!("database subset not supported yet for MongoDB source") } - let _ = read_and_transform(reader, options, query_callback)?; + read_and_transform(reader, options, query_callback)?; Ok(()) } } diff --git a/replibyte/src/source/mysql.rs b/replibyte/src/source/mysql.rs index 04dd820f..5da4a897 100644 --- a/replibyte/src/source/mysql.rs +++ b/replibyte/src/source/mysql.rs @@ -54,7 +54,7 @@ impl<'a> Mysql<'a> { impl<'a> Connector for Mysql<'a> { fn init(&mut self) -> Result<(), Error> { - let _ = binary_exists("mysqldump")?; + binary_exists("mysqldump")?; Ok(()) } @@ -198,7 +198,7 @@ pub fn read_and_transform( to_query( None, InsertIntoQuery { - table_name: table_name.to_string(), + table_name, columns, }, ), @@ -270,8 +270,8 @@ fn transform_columns( // -> position 4 // L Paren -> position X? // R Paren -> position X? - let column_names = get_column_names_from_insert_into_query(&tokens); - let column_values = get_column_values_from_insert_into_query(&tokens); + let column_names = get_column_names_from_insert_into_query(tokens); + let column_values = get_column_values_from_insert_into_query(tokens); assert_eq!( column_names.len(), column_values.len(), @@ -288,7 +288,7 @@ fn transform_columns( let column = match value_token { Token::Number(column_value, _) => { - if column_value.contains(".") { + if column_value.contains('.') { Column::FloatNumberValue( column_name.to_string(), column_value.parse::().unwrap(), @@ -301,7 +301,7 @@ fn transform_columns( } } Token::Char(column_value) => { - Column::CharValue(column_name.to_string(), column_value.clone()) + Column::CharValue(column_name.to_string(), *column_value) } Token::SingleQuotedString(column_value) => { Column::StringValue(column_name.to_string(), column_value.clone()) @@ -314,7 +314,7 @@ fn transform_columns( } Token::Word(w) if (w.value == "true" || w.value == "false") - && w.quote_style == None + && w.quote_style.is_none() && w.keyword == NoKeyword => { Column::BooleanValue(column_name.to_string(), w.value.parse::().unwrap()) @@ -341,28 +341,28 @@ fn transform_columns( } fn is_insert_into_statement(tokens: &Vec) -> bool { - match_keyword_at_position(Keyword::Insert, &tokens, 0) - && match_keyword_at_position(Keyword::Into, &tokens, 2) + match_keyword_at_position(Keyword::Insert, tokens, 0) + && match_keyword_at_position(Keyword::Into, tokens, 2) } fn is_create_table_statement(tokens: &Vec) -> bool { - match_keyword_at_position(Keyword::Create, &tokens, 0) - && match_keyword_at_position(Keyword::Table, &tokens, 2) + match_keyword_at_position(Keyword::Create, tokens, 0) + && match_keyword_at_position(Keyword::Table, tokens, 2) } fn get_row_type(tokens: &Vec) -> RowType { let mut row_type = RowType::Others; - if is_insert_into_statement(&tokens) { - if let Some(table_name) = get_single_quoted_string_value_at_position(&tokens, 4) { + if is_insert_into_statement(tokens) { + if let Some(table_name) = get_single_quoted_string_value_at_position(tokens, 4) { row_type = RowType::InsertInto { table_name: table_name.to_string(), }; } } - if is_create_table_statement(&tokens) { - if let Some(table_name) = get_single_quoted_string_value_at_position(&tokens, 4) { + if is_create_table_statement(tokens) { + if let Some(table_name) = get_single_quoted_string_value_at_position(tokens, 4) { row_type = RowType::CreateTable { table_name: table_name.to_string(), }; @@ -449,7 +449,7 @@ mod tests { let mut p = get_mysql(); assert!(p.init().is_ok()); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -461,7 +461,7 @@ mod tests { assert!(p.read(source_options, |_original_query, _query| {}).is_ok()); let p = get_invalid_mysql(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -477,7 +477,7 @@ mod tests { #[test] fn list_rows() { let p = get_mysql(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -486,8 +486,8 @@ mod tests { only_tables: &vec![], }; let _ = p.read(source_options, |original_query, query| { - assert!(original_query.data().len() > 0); - assert!(query.data().len() > 0); + assert!(!original_query.data().is_empty()); + assert!(!query.data().is_empty()); }); } @@ -497,7 +497,7 @@ mod tests { let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_insert_into_statement(&tokens), true); + assert!(is_insert_into_statement(&tokens)); let q = "CREATE TABLE `city` ( `ID` int NOT NULL AUTO_INCREMENT, @@ -512,7 +512,7 @@ CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_insert_into_statement(&tokens), false); + assert!(!is_insert_into_statement(&tokens)); } #[test] @@ -530,12 +530,12 @@ CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_create_table_statement(&tokens), true); + assert!(is_create_table_statement(&tokens)); let q = "INSERT INTO `customers` (`first_name`, `is_valid`) VALUES ('Romaric', true);"; let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_create_table_statement(&tokens), false); + assert!(!is_create_table_statement(&tokens)); } #[test] @@ -579,7 +579,7 @@ CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_create_table_statement(&tokens), true); + assert!(is_create_table_statement(&tokens)); let q = "CREATE TABLE `test` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -588,6 +588,6 @@ CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code let mut tokenizer = Tokenizer::new(q); let tokens = tokenizer.tokenize().unwrap(); - assert_eq!(is_create_table_statement(&tokens), true); + assert!(is_create_table_statement(&tokens)); } } diff --git a/replibyte/src/source/mysql_stdin.rs b/replibyte/src/source/mysql_stdin.rs index 56733073..692840e5 100644 --- a/replibyte/src/source/mysql_stdin.rs +++ b/replibyte/src/source/mysql_stdin.rs @@ -7,13 +7,10 @@ use crate::Source; use crate::SourceOptions; /// Source MySQL dump from STDIN +#[derive(Default)] pub struct MysqlStdin {} -impl Default for MysqlStdin { - fn default() -> Self { - Self {} - } -} + impl Connector for MysqlStdin { fn init(&mut self) -> Result<(), Error> { diff --git a/replibyte/src/source/postgres.rs b/replibyte/src/source/postgres.rs index 60ebae72..c150b8dd 100644 --- a/replibyte/src/source/postgres.rs +++ b/replibyte/src/source/postgres.rs @@ -200,7 +200,7 @@ pub fn subset( let named_subset_file = tempfile::NamedTempFile::new()?; let mut subset_file = named_subset_file.as_file(); - let _ = subset.read( + subset.read( |row| { match subset_file.write(format!("{}\n", row).as_bytes()) { Ok(_) => {} @@ -269,7 +269,7 @@ pub fn read_and_transform( to_query( Some(database_name.as_str()), InsertIntoQuery { - table_name: table_name.to_string(), + table_name, columns, }, ), @@ -310,7 +310,7 @@ pub fn read_and_parse_schema(reader: BufReader) -> Result<(), Error> let tokens = get_tokens_from_query_str(query.clone()); match get_row_type(&tokens) { RowType::CreateTable { - database_name, + database_name: _, table_name, } => { let column_schema = get_column_names_from_create_query(&tokens); @@ -359,8 +359,8 @@ fn transform_columns( //
-> position 6 // L Paren -> position X? // R Paren -> position X? - let column_names = get_column_names_from_insert_into_query(&tokens); - let column_values = get_column_values_from_insert_into_query(&tokens); + let column_names = get_column_names_from_insert_into_query(tokens); + let column_values = get_column_values_from_insert_into_query(tokens); assert_eq!( column_names.len(), column_values.len(), @@ -377,7 +377,7 @@ fn transform_columns( let column = match value_token { Token::Number(column_value, _) => { - if column_value.contains(".") { + if column_value.contains('.') { Column::FloatNumberValue( column_name.to_string(), column_value.parse::().unwrap(), @@ -390,7 +390,7 @@ fn transform_columns( } } Token::Char(column_value) => { - Column::CharValue(column_name.to_string(), column_value.clone()) + Column::CharValue(column_name.to_string(), *column_value) } Token::SingleQuotedString(column_value) => { Column::StringValue(column_name.to_string(), column_value.clone()) @@ -403,7 +403,7 @@ fn transform_columns( } Token::Word(w) if (w.value == "true" || w.value == "false") - && w.quote_style == None + && w.quote_style.is_none() && w.keyword == NoKeyword => { Column::BooleanValue(column_name.to_string(), w.value.parse::().unwrap()) @@ -431,26 +431,26 @@ fn transform_columns( } fn is_insert_into_statement(tokens: &Vec) -> bool { - match_keyword_at_position(Keyword::Insert, &tokens, 0) - && match_keyword_at_position(Keyword::Into, &tokens, 2) + match_keyword_at_position(Keyword::Insert, tokens, 0) + && match_keyword_at_position(Keyword::Into, tokens, 2) } fn is_create_table_statement(tokens: &Vec) -> bool { - match_keyword_at_position(Keyword::Create, &tokens, 0) - && match_keyword_at_position(Keyword::Table, &tokens, 2) + match_keyword_at_position(Keyword::Create, tokens, 0) + && match_keyword_at_position(Keyword::Table, tokens, 2) } fn is_alter_table_statement(tokens: &Vec) -> bool { - match_keyword_at_position(Keyword::Alter, &tokens, 0) - && match_keyword_at_position(Keyword::Table, &tokens, 2) + match_keyword_at_position(Keyword::Alter, tokens, 0) + && match_keyword_at_position(Keyword::Table, tokens, 2) } fn get_row_type(tokens: &Vec) -> RowType { let mut row_type = RowType::Others; - if is_insert_into_statement(&tokens) { - if let Some(database_name) = get_word_value_at_position(&tokens, 4) { - if let Some(table_name) = get_word_value_at_position(&tokens, 6) { + if is_insert_into_statement(tokens) { + if let Some(database_name) = get_word_value_at_position(tokens, 4) { + if let Some(table_name) = get_word_value_at_position(tokens, 6) { row_type = RowType::InsertInto { database_name: database_name.to_string(), table_name: table_name.to_string(), @@ -459,9 +459,9 @@ fn get_row_type(tokens: &Vec) -> RowType { } } - if is_create_table_statement(&tokens) { - if let Some(database_name) = get_word_value_at_position(&tokens, 4) { - if let Some(table_name) = get_word_value_at_position(&tokens, 6) { + if is_create_table_statement(tokens) { + if let Some(database_name) = get_word_value_at_position(tokens, 4) { + if let Some(table_name) = get_word_value_at_position(tokens, 6) { row_type = RowType::CreateTable { database_name: database_name.to_string(), table_name: table_name.to_string(), @@ -470,21 +470,21 @@ fn get_row_type(tokens: &Vec) -> RowType { } } - if is_alter_table_statement(&tokens) { - let database_name_pos = if match_keyword_at_position(Keyword::Only, &tokens, 4) { + if is_alter_table_statement(tokens) { + let database_name_pos = if match_keyword_at_position(Keyword::Only, tokens, 4) { 6 } else { 4 }; - let table_name_pos = if match_keyword_at_position(Keyword::Only, &tokens, 4) { + let table_name_pos = if match_keyword_at_position(Keyword::Only, tokens, 4) { 8 } else { 6 }; - if let Some(database_name) = get_word_value_at_position(&tokens, database_name_pos) { - if let Some(table_name) = get_word_value_at_position(&tokens, table_name_pos) { + if let Some(database_name) = get_word_value_at_position(tokens, database_name_pos) { + if let Some(table_name) = get_word_value_at_position(tokens, table_name_pos) { row_type = RowType::AlterTable { database_name: database_name.to_string(), table_name: table_name.to_string(), @@ -512,7 +512,7 @@ fn to_query(database: Option<&str>, query: InsertIntoQuery) -> Query { } Column::StringValue(column_name, value) => { column_names.push(column_name); - values.push(format!("'{}'", value.replace("'", "''"))); + values.push(format!("'{}'", value.replace('\'', "''"))); } Column::CharValue(column_name, value) => { column_names.push(column_name); @@ -574,7 +574,7 @@ mod tests { #[test] fn connect() { let p = get_postgres(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -583,10 +583,10 @@ mod tests { only_tables: &vec![], }; - assert!(p.read(source_options, |original_query, query| {}).is_ok()); + assert!(p.read(source_options, |_original_query, _query| {}).is_ok()); let p = get_invalid_postgres(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -595,13 +595,13 @@ mod tests { only_tables: &vec![], }; - assert!(p.read(source_options, |original_query, query| {}).is_err()); + assert!(p.read(source_options, |_original_query, _query| {}).is_err()); } #[test] fn list_rows() { let p = get_postgres(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let transformers = vec![t1]; let source_options = SourceOptions { transformers: &transformers, @@ -611,8 +611,8 @@ mod tests { }; let _ = p.read(source_options, |original_query, query| { - assert!(original_query.data().len() > 0); - assert!(query.data().len() > 0); + assert!(!original_query.data().is_empty()); + assert!(!query.data().is_empty()); }); } @@ -721,7 +721,7 @@ mod tests { let table_name = "employees"; let column_name_to_obfuscate = "last_name"; - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let t2: Box = Box::new(RandomTransformer::new( database_name, table_name, @@ -737,8 +737,8 @@ mod tests { }; let _ = p.read(source_options, |original_query, query| { - assert!(query.data().len() > 0); - assert!(query.data().len() > 0); + assert!(!query.data().is_empty()); + assert!(!query.data().is_empty()); let query_str = str::from_utf8(query.data()).unwrap(); @@ -761,7 +761,7 @@ mod tests { let database_name = "public"; let table_name = "employees"; - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let skip_employees_table = SkipConfig { database: database_name.to_string(), table: table_name.to_string(), @@ -778,8 +778,8 @@ mod tests { }; let _ = p.read(source_options, |_original_query, query| { - assert!(query.data().len() > 0); - assert!(query.data().len() > 0); + assert!(!query.data().is_empty()); + assert!(!query.data().is_empty()); let query_str = str::from_utf8(query.data()).unwrap(); let unexpected_insert_into = format!("INSERT INTO {}.{}", database_name, table_name); @@ -812,7 +812,7 @@ mod tests { #[test] fn subset_options() { let p = get_postgres(); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let source_options = SourceOptions { transformers: &vec![t1], @@ -830,7 +830,7 @@ mod tests { let mut rows_percent_50 = vec![]; let _ = p.read(source_options, |_original_query, query| { - assert!(query.data().len() > 0); + assert!(!query.data().is_empty()); rows_percent_50.push(String::from_utf8_lossy(query.data().as_slice()).to_string()); }); @@ -849,7 +849,7 @@ mod tests { // check that there is no duplicated rows assert_eq!(x.len(), y.len()); - let t1: Box = Box::new(TransientTransformer::default()); + let t1: Box = Box::::default(); let source_options = SourceOptions { transformers: &vec![t1], @@ -867,7 +867,7 @@ mod tests { let mut rows_percent_30 = vec![]; let _ = p.read(source_options, |_original_query, query| { - assert!(query.data().len() > 0); + assert!(!query.data().is_empty()); rows_percent_30.push(String::from_utf8_lossy(query.data().as_slice()).to_string()); }); diff --git a/replibyte/src/source/postgres_stdin.rs b/replibyte/src/source/postgres_stdin.rs index 8ad11590..8b31fd3f 100644 --- a/replibyte/src/source/postgres_stdin.rs +++ b/replibyte/src/source/postgres_stdin.rs @@ -7,13 +7,10 @@ use crate::Source; use crate::SourceOptions; /// Source Postgres dump from STDIN +#[derive(Default)] pub struct PostgresStdin {} -impl Default for PostgresStdin { - fn default() -> Self { - Self {} - } -} + impl Connector for PostgresStdin { fn init(&mut self) -> Result<(), Error> { diff --git a/replibyte/src/tasks/full_dump.rs b/replibyte/src/tasks/full_dump.rs index 907d271a..ab053a9b 100644 --- a/replibyte/src/tasks/full_dump.rs +++ b/replibyte/src/tasks/full_dump.rs @@ -42,7 +42,7 @@ where mut progress_callback: F, ) -> Result<(), Error> { // initialize the source - let _ = self.source.init()?; + self.source.init()?; let (tx, rx) = mpsc::sync_channel::>(1); let datastore = self.datastore; @@ -59,7 +59,7 @@ where }; if let Ok((chunk_part, queries)) = result { - let _ = match datastore.write(chunk_part, to_bytes(queries)) { + match datastore.write(chunk_part, to_bytes(queries)) { Ok(_) => {} Err(err) => return Err(Error::new(ErrorKind::Other, format!("{}", err))), }; @@ -82,7 +82,7 @@ where buffer_size * (chunk_part as usize + 1), ); - let _ = self.source.read(self.options, |_original_query, query| { + self.source.read(self.options, |_original_query, query| { if consumed_buffer_size + query.data().len() > buffer_size { chunk_part += 1; consumed_buffer_size = 0; @@ -91,7 +91,7 @@ where let message = Message::Data((chunk_part, queries.clone())); let _ = tx.send(message); // FIXME catch SendError? - let _ = queries.clear(); + queries.clear(); } consumed_buffer_size += query.data().len(); diff --git a/replibyte/src/tasks/full_restore.rs b/replibyte/src/tasks/full_restore.rs index e2a7dadf..527a0bc1 100644 --- a/replibyte/src/tasks/full_restore.rs +++ b/replibyte/src/tasks/full_restore.rs @@ -39,11 +39,11 @@ where D: Destination, { fn run( - mut self, + self, mut progress_callback: F, ) -> Result<(), Error> { // initialize the destination - let _ = self.destination.init()?; + self.destination.init()?; // bound to 1 to avoid eating too much memory if we download the dump faster than we ingest it let (tx, rx) = mpsc::sync_channel::>(1); @@ -62,7 +62,7 @@ where let datastore = datastore; let read_options = read_options; - let _ = match datastore.read(&read_options, &mut |data| { + match datastore.read(&read_options, &mut |data| { let _ = tx.send(Message::Data(data)); }) { Ok(_) => {} @@ -81,7 +81,7 @@ where progress_callback(data.len(), dump.size); - let _ = self.destination.write(data)?; + self.destination.write(data)?; } // wait for end of download execution diff --git a/replibyte/src/telemetry.rs b/replibyte/src/telemetry.rs index 9672fe3e..b9224c48 100644 --- a/replibyte/src/telemetry.rs +++ b/replibyte/src/telemetry.rs @@ -36,7 +36,7 @@ pub struct TelemetryClient { impl TelemetryClient { pub fn new>(options: C) -> Self { let client = HttpClient::builder() - .timeout(Some(TIMEOUT.clone())) + .timeout(Some(*TIMEOUT)) .build() .unwrap(); // Unwrap here is as safe as `HttpClient::new` TelemetryClient { @@ -69,10 +69,10 @@ impl TelemetryClient { config: &Config, sub_command: &SubCommand, args: &Vec, - execution_time_in_millis: Option, + _execution_time_in_millis: Option, ) -> Result<(), Error> { let mut props = HashMap::new(); - let _ = props.insert("args".to_string(), args.join(" ").to_string()); + let _ = props.insert("args".to_string(), args.join(" ")); props.insert( "encryption_used".to_string(), diff --git a/replibyte/src/transformer/credit_card.rs b/replibyte/src/transformer/credit_card.rs index 9218cf4b..329e0a52 100644 --- a/replibyte/src/transformer/credit_card.rs +++ b/replibyte/src/transformer/credit_card.rs @@ -5,6 +5,7 @@ use fake::locales::EN; use fake::Fake; /// This struct is dedicated to replacing a credit card string. +#[derive(Default)] pub struct CreditCardTransformer { database_name: String, table_name: String, @@ -24,15 +25,7 @@ impl CreditCardTransformer { } } -impl Default for CreditCardTransformer { - fn default() -> Self { - CreditCardTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for CreditCardTransformer { fn id(&self) -> &str { diff --git a/replibyte/src/transformer/email.rs b/replibyte/src/transformer/email.rs index 1a48dfa6..9978a83e 100644 --- a/replibyte/src/transformer/email.rs +++ b/replibyte/src/transformer/email.rs @@ -5,6 +5,7 @@ use fake::locales::EN; use fake::Fake; /// This struct is dedicated to replacing a string by an email address. +#[derive(Default)] pub struct EmailTransformer { database_name: String, table_name: String, @@ -24,15 +25,7 @@ impl EmailTransformer { } } -impl Default for EmailTransformer { - fn default() -> Self { - EmailTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for EmailTransformer { fn id(&self) -> &str { diff --git a/replibyte/src/transformer/first_name.rs b/replibyte/src/transformer/first_name.rs index c12b4a9b..a2c4e29e 100644 --- a/replibyte/src/transformer/first_name.rs +++ b/replibyte/src/transformer/first_name.rs @@ -5,6 +5,7 @@ use fake::locales::EN; use fake::Fake; /// This struct is dedicated to replacing string by a first name. +#[derive(Default)] pub struct FirstNameTransformer { database_name: String, table_name: String, @@ -24,15 +25,7 @@ impl FirstNameTransformer { } } -impl Default for FirstNameTransformer { - fn default() -> Self { - FirstNameTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for FirstNameTransformer { fn id(&self) -> &str { @@ -62,7 +55,7 @@ impl Transformer for FirstNameTransformer { Column::FloatNumberValue(column_name, value) } Column::StringValue(column_name, value) => { - let new_value = if value == "" { + let new_value = if value.is_empty() { "".to_string() } else { FirstName(EN).fake() diff --git a/replibyte/src/transformer/keep_first_char.rs b/replibyte/src/transformer/keep_first_char.rs index 7b17511e..0cb16d04 100644 --- a/replibyte/src/transformer/keep_first_char.rs +++ b/replibyte/src/transformer/keep_first_char.rs @@ -1,6 +1,7 @@ use crate::transformer::Transformer; use crate::types::Column; +#[derive(Default)] pub struct KeepFirstCharTransformer { database_name: String, table_name: String, @@ -20,15 +21,7 @@ impl KeepFirstCharTransformer { } } -impl Default for KeepFirstCharTransformer { - fn default() -> Self { - KeepFirstCharTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for KeepFirstCharTransformer { fn id(&self) -> &str { @@ -68,7 +61,7 @@ impl Transformer for KeepFirstCharTransformer { Column::StringValue(column_name, value) => { let new_value = match value.len() { len if len > 1 => { - if let Some(first_char) = value.chars().nth(0) { + if let Some(first_char) = value.chars().next() { first_char.to_string() } else { "".to_string() diff --git a/replibyte/src/transformer/mod.rs b/replibyte/src/transformer/mod.rs index 4dcd1437..25c5e91c 100644 --- a/replibyte/src/transformer/mod.rs +++ b/replibyte/src/transformer/mod.rs @@ -24,15 +24,15 @@ pub mod custom_wasm; pub fn transformers() -> Vec> { vec![ - Box::new(EmailTransformer::default()), - Box::new(FirstNameTransformer::default()), - Box::new(PhoneNumberTransformer::default()), - Box::new(RandomTransformer::default()), - Box::new(KeepFirstCharTransformer::default()), - Box::new(TransientTransformer::default()), - Box::new(CreditCardTransformer::default()), - Box::new(RedactedTransformer::default()), - Box::new(CustomWasmTransformer::default()), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), ] } diff --git a/replibyte/src/transformer/phone_number.rs b/replibyte/src/transformer/phone_number.rs index 9760fcf9..09c80386 100644 --- a/replibyte/src/transformer/phone_number.rs +++ b/replibyte/src/transformer/phone_number.rs @@ -5,6 +5,7 @@ use fake::locales::EN; use fake::Fake; /// This struct is dedicated to replacing a string by an email address. +#[derive(Default)] pub struct PhoneNumberTransformer { database_name: String, table_name: String, @@ -24,15 +25,7 @@ impl PhoneNumberTransformer { } } -impl Default for PhoneNumberTransformer { - fn default() -> Self { - PhoneNumberTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for PhoneNumberTransformer { fn id(&self) -> &str { diff --git a/replibyte/src/transformer/random.rs b/replibyte/src/transformer/random.rs index 8e6b2fa9..37ed2ae5 100644 --- a/replibyte/src/transformer/random.rs +++ b/replibyte/src/transformer/random.rs @@ -4,6 +4,7 @@ use rand::distributions::Alphanumeric; use rand::Rng; /// This struct is dedicated to generating random elements. +#[derive(Default)] pub struct RandomTransformer { database_name: String, table_name: String, @@ -23,15 +24,7 @@ impl RandomTransformer { } } -impl Default for RandomTransformer { - fn default() -> Self { - RandomTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl Transformer for RandomTransformer { fn id(&self) -> &str { diff --git a/replibyte/src/transformer/redacted.rs b/replibyte/src/transformer/redacted.rs index 26b53866..26777287 100644 --- a/replibyte/src/transformer/redacted.rs +++ b/replibyte/src/transformer/redacted.rs @@ -4,6 +4,7 @@ use crate::transformer::Transformer; use crate::types::Column; /// This struct is dedicated to redact a string with a specific character (default to '*'). +#[derive(Default)] pub struct RedactedTransformer { database_name: String, table_name: String, @@ -45,16 +46,7 @@ impl RedactedTransformer { } } -impl Default for RedactedTransformer { - fn default() -> Self { - RedactedTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - options: RedactedTransformerOptions::default(), - } - } -} + impl Transformer for RedactedTransformer { fn id(&self) -> &str { diff --git a/replibyte/src/transformer/transient.rs b/replibyte/src/transformer/transient.rs index a8facaea..76acda8f 100644 --- a/replibyte/src/transformer/transient.rs +++ b/replibyte/src/transformer/transient.rs @@ -2,21 +2,14 @@ use crate::transformer::Transformer; use crate::types::Column; /// This transformer will not make any changes. +#[derive(Default)] pub struct TransientTransformer { database_name: String, table_name: String, column_name: String, } -impl Default for TransientTransformer { - fn default() -> Self { - TransientTransformer { - database_name: String::default(), - table_name: String::default(), - column_name: String::default(), - } - } -} + impl TransientTransformer { pub fn new(database_name: S, table_name: S, column_name: S) -> Self diff --git a/replibyte/src/utils.rs b/replibyte/src/utils.rs index 0ac0ec0e..5e48749c 100644 --- a/replibyte/src/utils.rs +++ b/replibyte/src/utils.rs @@ -24,10 +24,10 @@ pub fn table() -> Table { pub fn to_human_readable_unit(bytes: usize) -> String { match bytes { 0..=1023 => format!("{} Bytes", bytes), - 1024..=1023_999 => format!("{:.2} kB", bytes / 1000), - 1024_000..=1023_999_999 => format!("{:.2} MB", bytes / 1_000_000), - 1024_000_000..=1023_999_999_999 => format!("{:.2} MB", bytes / 1_000_000_000), - 1024_000_000_000..=1023_999_999_999_999 => format!("{:.2} GB", bytes / 1_000_000_000_000), + 1024..=1_023_999 => format!("{:.2} kB", bytes / 1000), + 1_024_000..=1_023_999_999 => format!("{:.2} MB", bytes / 1_000_000), + 1_024_000_000..=1_023_999_999_999 => format!("{:.2} MB", bytes / 1_000_000_000), + 1_024_000_000_000..=1_023_999_999_999_999 => format!("{:.2} GB", bytes / 1_000_000_000_000), _ => format!("{:.2} TB", bytes / 1_000_000_000_000_000), } } @@ -52,7 +52,7 @@ pub fn wait_for_command(process: &mut Child) -> Result<(), Error> { if let Some(stderr) = process.stderr.take().as_mut() { let mut buffer = String::new(); let error = match stderr.read_to_string(&mut buffer) { - Ok(_) => Error::new(ErrorKind::Other, format!("{}", buffer)), + Ok(_) => Error::new(ErrorKind::Other, buffer.to_string()), Err(err) => Error::new(ErrorKind::Other, format!("{}", err)), }; @@ -64,7 +64,7 @@ pub fn wait_for_command(process: &mut Child) -> Result<(), Error> { return Err(Error::new( ErrorKind::Other, - format!("command error: {}", exit_status.to_string()), + format!("command error: {}", exit_status), )); } diff --git a/subset/src/dedup.rs b/subset/src/dedup.rs index 2dd02b8a..227dfc9e 100644 --- a/subset/src/dedup.rs +++ b/subset/src/dedup.rs @@ -56,7 +56,7 @@ pub fn does_line_exist( return Ok(true); } - let _ = buf.clear(); + buf.clear(); } Ok(false) diff --git a/subset/src/lib.rs b/subset/src/lib.rs index 366ecafe..bda48623 100644 --- a/subset/src/lib.rs +++ b/subset/src/lib.rs @@ -93,8 +93,7 @@ impl SubsetTable { subset_tables .iter() - .filter(|subset_table| related_tables.contains(subset_table.table.as_str())) - .map(|subset_table| *subset_table) + .filter(|subset_table| related_tables.contains(subset_table.table.as_str())).copied() .collect::>() } } diff --git a/subset/src/postgres.rs b/subset/src/postgres.rs index 4a5cbf15..4a1947d4 100644 --- a/subset/src/postgres.rs +++ b/subset/src/postgres.rs @@ -133,7 +133,7 @@ impl<'a> PostgresSubset<'a> { // find the subset table from this row let row_subset_table = self .subset_table_by_database_and_table_name - .get(&(row_database.to_string(), row_table.to_string())) + .get(&(row_database, row_table)) .unwrap(); let row_column_names = get_column_names_from_insert_into_query(&row_tokens); @@ -159,7 +159,7 @@ impl<'a> PostgresSubset<'a> { } }; - let _ = filter_insert_into_rows( + filter_insert_into_rows( row_relation.to_property.as_str(), value.as_str(), self.dump_reader(), @@ -185,11 +185,11 @@ impl<'a> Subset for PostgresSubset<'a> { fn read( &self, mut data: F, - mut progress: P, + progress: P, ) -> Result<(), Error> { let temp_dir = tempfile::tempdir()?; - let _ = read( + read( self, |line| { if line.contains("INSERT INTO") { @@ -230,7 +230,7 @@ fn read( // send schema header let table_stats_values = table_stats.values().collect::>(); - let _ = dump_header( + dump_header( postgres_subset.dump_reader(), last_header_row_idx(&table_stats_values), |row| { @@ -255,7 +255,7 @@ fn read( // send INSERT INTO rows for row in rows { let start_time = utils::epoch_millis(); - let _ = postgres_subset.visits(row, &table_stats, &mut data)?; + postgres_subset.visits(row, &table_stats, &mut data)?; processed_rows += 1; @@ -273,7 +273,7 @@ fn read( if table_stats.database.as_str() == passthrough_table.database && table_stats.table.as_str() == passthrough_table.table { - let _ = list_insert_into_rows(postgres_subset.dump_reader(), table_stats, |row| { + list_insert_into_rows(postgres_subset.dump_reader(), table_stats, |row| { data(row.to_string()); })?; } @@ -281,7 +281,7 @@ fn read( } // send schema footer - let _ = dump_footer( + dump_footer( postgres_subset.dump_reader(), first_footer_row_idx(&table_stats_values), |row| { @@ -319,7 +319,7 @@ fn list_percent_of_insert_into_rows( let modulo = (table_stats.total_rows as f32 / total_rows_to_pick) as usize; let mut counter = 1usize; - let _ = list_insert_into_rows(dump_reader, table_stats, |rows| { + list_insert_into_rows(dump_reader, table_stats, |rows| { if counter % modulo == 0 { insert_into_rows.push(rows.to_string()); } @@ -336,7 +336,7 @@ fn list_insert_into_rows( mut rows: F, ) -> Result<(), Error> { let mut query_idx = 0usize; - let _ = list_sql_queries_from_dump_reader(dump_reader, |query| { + list_sql_queries_from_dump_reader(dump_reader, |query| { let mut query_res = ListQueryResult::Continue; // optimization to avoid tokenizing unnecessary queries -- it's a 13x optim (benched) @@ -351,7 +351,7 @@ fn list_insert_into_rows( && get_word_value_at_position(&tokens, 4) == Some(table_stats.database.as_str()) && get_word_value_at_position(&tokens, 6) == Some(table_stats.table.as_str()) { - rows(query.as_ref()); + rows(query); } } @@ -392,7 +392,7 @@ fn filter_insert_into_rows( }; let mut query_idx = 0usize; - let _ = list_sql_queries_from_dump_reader(dump_reader, |query| { + list_sql_queries_from_dump_reader(dump_reader, |query| { let mut query_res = ListQueryResult::Continue; // optimization to avoid tokenizing unnecessary queries -- it's a 13x optim (benched) @@ -457,7 +457,7 @@ fn dump_header( mut rows: F, ) -> Result<(), Error> { let mut query_idx = 0usize; - let _ = list_sql_queries_from_dump_reader(dump_reader, |query| { + list_sql_queries_from_dump_reader(dump_reader, |query| { let mut query_res = ListQueryResult::Continue; if query_idx <= last_header_row_idx { @@ -484,7 +484,7 @@ fn dump_footer( mut rows: F, ) -> Result<(), Error> { let mut query_idx = 0usize; - let _ = list_sql_queries_from_dump_reader(dump_reader, |query| { + list_sql_queries_from_dump_reader(dump_reader, |query| { if query_idx >= first_footer_row_idx { rows(query) } @@ -503,10 +503,10 @@ fn table_stats_by_database_and_table_name( HashMap::<(Database, Table), TableStats>::new(); let mut query_idx = 0usize; - let _ = list_sql_queries_from_dump_reader(dump_reader, |query| { + list_sql_queries_from_dump_reader(dump_reader, |query| { let tokens = get_tokens_from_query_str(query); - let _ = match get_create_table_database_and_table_name(&tokens) { + match get_create_table_database_and_table_name(&tokens) { Some((database, table)) => { table_stats_by_database_and_table_name.insert( (database.clone(), table.clone()), @@ -575,8 +575,7 @@ fn trim_tokens(tokens: &Vec, keyword: Keyword) -> Vec { .skip_while(|token| match *token { Token::Word(word) if word.keyword == keyword => false, _ => true, - }) - .map(|token| token.clone()) // FIXME - do not clone token + }).cloned() // FIXME - do not clone token .collect::>() } @@ -598,7 +597,7 @@ fn get_subset_table_by_database_and_table_name( } if let Some(fk) = get_alter_table_foreign_key(&tokens) { - let _ = match subset_table_by_database_and_table_name + match subset_table_by_database_and_table_name .get_mut(&(fk.from_database, fk.from_table)) { Some(subset_table) => { @@ -620,7 +619,7 @@ fn get_subset_table_by_database_and_table_name( } fn get_create_table_database_and_table_name(tokens: &Vec) -> Option<(Database, Table)> { - let tokens = trim_tokens(&tokens, Keyword::Create); + let tokens = trim_tokens(tokens, Keyword::Create); if tokens.is_empty() { return None; @@ -640,7 +639,7 @@ fn get_create_table_database_and_table_name(tokens: &Vec) -> Option<(Data } fn get_insert_into_database_and_table_name(tokens: &Vec) -> Option<(Database, Table)> { - let tokens = trim_tokens(&tokens, Keyword::Insert); + let tokens = trim_tokens(tokens, Keyword::Insert); if tokens.is_empty() { return None; @@ -660,7 +659,7 @@ fn get_insert_into_database_and_table_name(tokens: &Vec) -> Option<(Datab } fn get_alter_table_foreign_key(tokens: &Vec) -> Option { - let tokens = trim_tokens(&tokens, Keyword::Alter); + let tokens = trim_tokens(tokens, Keyword::Alter); if tokens.is_empty() { return None; @@ -699,8 +698,7 @@ fn get_alter_table_foreign_key(tokens: &Vec) -> Option { .skip_while(|token| match token { Token::Word(word) if word.keyword == Keyword::Foreign => false, _ => true, - }) - .map(|token| token.clone()) + }).cloned() .collect::>(); let from_property = match get_word_value_at_position(&next_foreign_tokens, 5) { @@ -803,7 +801,7 @@ ALTER TABLE ONLY public.territories #[test] fn check_subset_table() { let m = get_subset_table_by_database_and_table_name(dump_reader()).unwrap(); - assert!(m.len() > 0); + assert!(!m.is_empty()); let t = m .get(&("public".to_string(), "customer_demographics".to_string())) @@ -834,7 +832,7 @@ ALTER TABLE ONLY public.territories #[test] fn check_table_stats() { let table_stats = table_stats_by_database_and_table_name(dump_reader()).unwrap(); - assert!(table_stats.len() > 0); + assert!(!table_stats.is_empty()); // TODO add more tests to check table.rows size } @@ -884,7 +882,7 @@ ALTER TABLE ONLY public.territories assert!(idx > 0); let mut rows = vec![]; - let _ = dump_header(dump_reader(), idx, |row| { + dump_header(dump_reader(), idx, |row| { rows.push(row.to_string()); }) .unwrap(); @@ -905,7 +903,7 @@ ALTER TABLE ONLY public.territories assert!(idx > 0); let mut rows = vec![]; - let _ = dump_footer(dump_reader(), idx, |row| { + dump_footer(dump_reader(), idx, |row| { rows.push(row.to_string()); }) .unwrap();