From feaab2e8434401647086ce183980f98a29c5ba6f Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sun, 26 Feb 2023 09:24:09 -0500 Subject: [PATCH] More linting. --- src/main.rs | 34 +++++++++++++++++----------------- src/util.rs | 2 +- src/webui/mod.rs | 15 ++++----------- src/webui/views.rs | 4 ++-- src/webui/worker.rs | 4 ++-- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main.rs b/src/main.rs index b74fb81..e5ed0ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,14 +251,14 @@ fn process_process_events_command_line( } fn process_run_wui_command_line( - connFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic, ) -> CustomResult<()> { debug!("Processing run wui command line {:?}.", m); let port = m.get_one::("port").unwrap_or(&2222); let enable_template_autoreload = m.get_flag("enable-template-autoreload"); - logic.run_webui(connFact, *port, enable_template_autoreload) + logic.run_webui(conn_fact, *port, enable_template_autoreload) } fn process_securities_command_line( @@ -290,26 +290,26 @@ fn process_events_command_line( } fn process_wui_command_line( - connFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic, ) -> CustomResult<()> { debug!("Processing wui command line {:?}.", m); match m.subcommand() { Some(("run", run_wui_match)) => { - process_run_wui_command_line(connFact, run_wui_match, logic) + process_run_wui_command_line(conn_fact, run_wui_match, logic) } _ => unreachable!(), } } fn process_command_line( - connFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic, ) -> CustomResult<()> { debug!("Processing command line {:?}.", m); - let mut conn = connFact.connection()?; + let mut conn = conn_fact.connection()?; match m.subcommand() { Some(("users", user_match)) => process_user_command_line(&mut conn, user_match, logic), Some(("securities", securities_match)) => { @@ -318,7 +318,7 @@ fn process_command_line( Some(("events", events_match)) => { process_events_command_line(&mut conn, events_match, logic) } - Some(("wui", wui_match)) => process_wui_command_line(connFact, wui_match, logic), + Some(("wui", wui_match)) => process_wui_command_line(conn_fact, wui_match, logic), _ => { println!("Received un parsable command. {:?}", m.subcommand()); unreachable!(); @@ -437,7 +437,7 @@ mod cli_test { ]); let mut logic = TestCommandLineLogic::new(); let mut conn = Connection::open_in_memory().unwrap(); - process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?; + process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?; assert_eq!(logic.create_user_count, 1); Ok(()) } @@ -448,7 +448,7 @@ mod cli_test { let m = cmd.get_matches_from(vec!["test", "users", "ls"]); let mut logic = TestCommandLineLogic::new(); let mut conn = Connection::open_in_memory().unwrap(); - process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?; + process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?; assert_eq!(logic.list_user_count, 1); Ok(()) } @@ -459,7 +459,7 @@ mod cli_test { let m = cmd.get_matches_from(vec!["test", "securities", "ls"]); let mut logic = TestCommandLineLogic::new(); let mut conn = Connection::open_in_memory().unwrap(); - process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?; + process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?; assert_eq!(logic.list_securities_count, 1); Ok(()) } @@ -470,7 +470,7 @@ mod cli_test { let m = cmd.get_matches_from(vec!["test", "events", "process", "/dev/null"]); let mut logic = TestCommandLineLogic::new(); let mut conn = Connection::open_in_memory().unwrap(); - process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?; + process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?; assert_eq!(logic.process_events_count, 1); Ok(()) } @@ -481,7 +481,7 @@ mod cli_test { let m = cmd.get_matches_from(vec!["test", "wui", "run"]); let mut logic = TestCommandLineLogic::new(); let mut conn = Connection::open_in_memory().unwrap(); - process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?; + process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?; assert_eq!(logic.run_webui_count, 1); Ok(()) } @@ -532,12 +532,12 @@ impl CommandLineUserLogic for ProCommandLineLogic { fn run_webui( &mut self, - connFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, port: u16, enable_template_autoreload: bool, ) -> CustomResult<()> { info!("Serving web-ui on port {:?}", port); - web_ui_main(connFact, port, enable_template_autoreload) + web_ui_main(conn_fact, port, enable_template_autoreload) } } @@ -560,9 +560,9 @@ fn main() -> CustomResult<()> { let m = command.get_matches(); set_logger(&m); - let connFactory = get_connection(&m); + let conn_factory = get_connection(&m); - apply_migrations(&mut connFactory.connection()?).unwrap(); + apply_migrations(&mut conn_factory.connection()?).unwrap(); let mut logic = ProCommandLineLogic::new(); - process_command_line(connFactory, &m, &mut logic) + process_command_line(conn_factory, &m, &mut logic) } diff --git a/src/util.rs b/src/util.rs index 951dd66..a9e5743 100644 --- a/src/util.rs +++ b/src/util.rs @@ -68,7 +68,7 @@ impl SQLiteConnectionFactory { } } - pub fn inMemory() -> SQLiteConnectionFactory { + pub fn in_memory() -> SQLiteConnectionFactory { SQLiteConnectionFactory { creator: SQLiteConnectionCreator::Ephemeral(EphemeralSQLiteConnectionCreator {}), } diff --git a/src/webui/mod.rs b/src/webui/mod.rs index 25a7d53..84503b8 100644 --- a/src/webui/mod.rs +++ b/src/webui/mod.rs @@ -24,13 +24,6 @@ use crate::webui::worker::{bob, event_processor_loop}; mod views; mod worker; -struct Service {} - -impl Service { - fn get_users(self) -> Vec { - vec!["to".to_string(), "foo".to_string()] - } -} struct MiniJinjaRenderer { tmpl_env: web::Data, @@ -84,7 +77,7 @@ fn create_auto_reloader(enable_template_autoreload: bool) -> AutoReloader { #[tokio::main] pub async fn web_ui_main( - connFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, port: u16, enable_template_autoreload: bool, ) -> CustomResult<()> { @@ -95,12 +88,12 @@ pub async fn web_ui_main( let tmpl_reloader = web::Data::new(tmpl_reloader); - let clonedConnFact = connFact.clone(); + let cloned_conn_fact = conn_fact.clone(); let server = HttpServer::new(move || { App::new() .app_data(tmpl_reloader.clone()) .app_data(web::Data::new(event_sender.clone())) - .app_data(web::Data::new(clonedConnFact.clone())) + .app_data(web::Data::new(cloned_conn_fact.clone())) .service( actix_files::Files::new("/static", "./resources/static/").use_last_modified(true), ) @@ -120,7 +113,7 @@ pub async fn web_ui_main( .unwrap(); let t1 = server.run().fuse(); - let t2 = event_processor_loop(connFact, event_receiver).fuse(); + let t2 = event_processor_loop(conn_fact, event_receiver).fuse(); let t3 = bob().fuse(); pin_mut!(t1, t2, t3); diff --git a/src/webui/views.rs b/src/webui/views.rs index afe4c19..07fabcf 100644 --- a/src/webui/views.rs +++ b/src/webui/views.rs @@ -25,9 +25,9 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result, + conn_factory: web::Data, ) -> actix_web::Result { - let conn = connFactory.readonly().unwrap(); // todo; to proper 500 + let conn = conn_factory.readonly().unwrap(); // todo; to proper 500 let service_factory = ServiceFactory::new(&conn); let user_service = service_factory.get_user_service(); let users = user_service.list_users().unwrap(); diff --git a/src/webui/worker.rs b/src/webui/worker.rs index 8bacdb6..585d98c 100644 --- a/src/webui/worker.rs +++ b/src/webui/worker.rs @@ -11,12 +11,12 @@ use crate::util::{CustomResult, SQLiteConnectionFactory}; // todo, all the "?" and handle the exceptions for real pub async fn event_processor_loop( - conFact: SQLiteConnectionFactory, + conn_fact: SQLiteConnectionFactory, r: async_channel::Receiver, ) -> CustomResult<()> { loop { let res = r.recv().await; - let mut conn = conFact.connection()?; + let mut conn = conn_fact.connection()?; match res { Ok(event) => process_event(&mut conn, event)?, Err(e) => {