From f7f8828c07bbccdb4b19488c54778f8246dcf706 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 12:17:41 +0300 Subject: [PATCH 01/17] feat(#9): xml storage init --- Cargo.toml | 2 ++ src/main.rs | 2 ++ src/xml/mod.rs | 22 ++++++++++++++++++++++ src/xml/storage.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 src/xml/mod.rs create mode 100644 src/xml/storage.rs diff --git a/Cargo.toml b/Cargo.toml index fe7fb4ff..a64318d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,5 +34,7 @@ authors = ["Aliaksei BialĂ­auski ", "Ivanchuk Ivan [dependencies] clippy = "0.0.302" +env_logger = "0.11.3" serde = "1.0.203" anyhow = "1.0.86" +log = { version = "0.4.21", features = [] } diff --git a/src/main.rs b/src/main.rs index 8b7800a8..93785867 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +mod xml; + fn main() { println!("Hello, world!"); } diff --git a/src/xml/mod.rs b/src/xml/mod.rs new file mode 100644 index 00000000..e263c1e6 --- /dev/null +++ b/src/xml/mod.rs @@ -0,0 +1,22 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +pub mod storage; diff --git a/src/xml/storage.rs b/src/xml/storage.rs new file mode 100644 index 00000000..b5595383 --- /dev/null +++ b/src/xml/storage.rs @@ -0,0 +1,46 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +use std::fs::File; + +use log::info; + +pub fn xml() { + let path = "fakehub.xml"; + info!("Initializing XML storage: {path}"); + File::create(path).unwrap(); + info!("{path} initialized."); +} + +#[cfg(test)] +mod tests { + use std::path::Path; + + use crate::xml::storage::xml; + + #[test] + fn creates_xml_storage() { + xml(); + let storage = "fakehub.xml"; + let exists = Path::new(storage).exists(); + assert!(exists, "storage file {storage} was not created, but should") + } +} From 7de02f0ff28e419192fae5f0ff0f05aa53012b18 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 12:22:52 +0300 Subject: [PATCH 02/17] feat(#9): init, clean --- src/xml/storage.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index b5595383..9da292e0 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -23,7 +23,7 @@ use std::fs::File; use log::info; -pub fn xml() { +pub fn init() { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); File::create(path).unwrap(); @@ -32,15 +32,21 @@ pub fn xml() { #[cfg(test)] mod tests { + use std::fs; use std::path::Path; + + use crate::xml::storage::init; - use crate::xml::storage::xml; + fn clean() { + fs::remove_file("fakehub.xml").unwrap(); + } #[test] fn creates_xml_storage() { - xml(); + init(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); - assert!(exists, "storage file {storage} was not created, but should") + assert!(exists, "storage file {storage} was not created, but should"); + clean(); } } From 31d4db5b8447fb2a0597eafff1e66de741323df7 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 12:25:19 +0300 Subject: [PATCH 03/17] feat(#9): clean fmt --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index 9da292e0..fc4a19ad 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -34,7 +34,7 @@ pub fn init() { mod tests { use std::fs; use std::path::Path; - + use crate::xml::storage::init; fn clean() { From 5bed624f59aa2b8f308e6deca1fde4daa4b5fc01 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 12:27:08 +0300 Subject: [PATCH 04/17] feat(#9): storage usage --- src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.rs b/src/main.rs index 93785867..e4934d40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use crate::xml::storage::init; + mod xml; fn main() { + init(); println!("Hello, world!"); } From 5a92c060b51c1f271cf36ddeac95ff32f3d353d8 Mon Sep 17 00:00:00 2001 From: Aliaksei Bialiauski Date: Wed, 5 Jun 2024 12:59:53 +0300 Subject: [PATCH 05/17] feat(#9): chars Co-authored-by: Ivan Ivanchuk --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index fc4a19ad..bdff1a42 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -27,7 +27,7 @@ pub fn init() { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); File::create(path).unwrap(); - info!("{path} initialized."); + info!("'{path}' initialized."); } #[cfg(test)] From 6cfc7b33d82b0a7d63144700df9da24807407671 Mon Sep 17 00:00:00 2001 From: Aliaksei Bialiauski Date: Wed, 5 Jun 2024 13:00:03 +0300 Subject: [PATCH 06/17] feat(#9): chars Co-authored-by: Ivan Ivanchuk --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index bdff1a42..fa435f17 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -46,7 +46,7 @@ mod tests { init(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); - assert!(exists, "storage file {storage} was not created, but should"); + assert!(exists, "storage file '{storage}' was not created, but should"); clean(); } } From b9c574898ee6c1b4b4cbb3ce374bb0c231266fe1 Mon Sep 17 00:00:00 2001 From: Aliaksei Bialiauski Date: Wed, 5 Jun 2024 13:00:15 +0300 Subject: [PATCH 07/17] feat(#9): touch Co-authored-by: Ivan Ivanchuk --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index fa435f17..eb1b981d 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -23,7 +23,7 @@ use std::fs::File; use log::info; -pub fn init() { +pub fn touch_storage() { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); File::create(path).unwrap(); From 72e04723d24465bbb1b477a53c074b8276c5af69 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 13:01:23 +0300 Subject: [PATCH 08/17] feat(#9): touch adjust --- src/xml/storage.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index eb1b981d..4b98c454 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -34,8 +34,7 @@ pub fn touch_storage() { mod tests { use std::fs; use std::path::Path; - - use crate::xml::storage::init; + use crate::xml::storage::touch_storage; fn clean() { fs::remove_file("fakehub.xml").unwrap(); @@ -43,7 +42,7 @@ mod tests { #[test] fn creates_xml_storage() { - init(); + touch_storage(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); assert!(exists, "storage file '{storage}' was not created, but should"); From 4bc3d1b09322d52b8cd86879acd6018f86e70348 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 13:39:12 +0300 Subject: [PATCH 09/17] feat(#9): error handling --- src/main.rs | 4 ++-- src/xml/storage.rs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index e4934d40..ebc3a230 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,11 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use crate::xml::storage::init; +use crate::xml::storage::touch_storage; mod xml; fn main() { - init(); + touch_storage(); println!("Hello, world!"); } diff --git a/src/xml/storage.rs b/src/xml/storage.rs index 4b98c454..b85d8567 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -1,3 +1,4 @@ +use std::fmt::Error; // The MIT License (MIT) // // Copyright (c) 2024 Aliaksei Bialiauski @@ -26,14 +27,24 @@ use log::info; pub fn touch_storage() { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); - File::create(path).unwrap(); - info!("'{path}' initialized."); + let creating = File::create(path); + let _ = match creating { + Ok(file) => { + info!("'{path}' initialized"); + Ok::(file) + } + Err(err) => { + panic!("fakehub storage failed to initialize in '{path}': {err}"); + } + }; } + #[cfg(test)] mod tests { use std::fs; use std::path::Path; + use crate::xml::storage::touch_storage; fn clean() { From 9622a5bbb4bb0afdebc5dfc57131ae5b89549a48 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 13:44:55 +0300 Subject: [PATCH 10/17] feat(#9): clean fmt --- src/xml/storage.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index b85d8567..4f0e80f4 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -39,7 +39,6 @@ pub fn touch_storage() { }; } - #[cfg(test)] mod tests { use std::fs; @@ -56,7 +55,10 @@ mod tests { touch_storage(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); - assert!(exists, "storage file '{storage}' was not created, but should"); + assert!( + exists, + "storage file '{storage}' was not created, but should" + ); clean(); } } From 7062ad5f35bf33e75071661d9d61f6151d721cc2 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 13:46:14 +0300 Subject: [PATCH 11/17] feat(#9): clean fmt --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index 4f0e80f4..fad73ffe 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -1,4 +1,3 @@ -use std::fmt::Error; // The MIT License (MIT) // // Copyright (c) 2024 Aliaksei Bialiauski @@ -20,6 +19,7 @@ use std::fmt::Error; // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use std::fmt::Error; use std::fs::File; use log::info; From 3ae99e24d1366db2c077376c8692e83fe40e795c Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 14:08:55 +0300 Subject: [PATCH 12/17] feat(#9): match --- src/main.rs | 2 +- src/xml/storage.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2566d391..078b8a0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use crate::xml::storage::touch_storage; #[tokio::main] async fn main() { - touch_storage(); + touch_storage().unwrap(); let app = Router::new().route("/", get(home::home)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); diff --git a/src/xml/storage.rs b/src/xml/storage.rs index fad73ffe..f811db12 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -24,19 +24,19 @@ use std::fs::File; use log::info; -pub fn touch_storage() { +pub fn touch_storage() -> Result { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); let creating = File::create(path); - let _ = match creating { + match creating { Ok(file) => { info!("'{path}' initialized"); - Ok::(file) + Ok(file) } Err(err) => { - panic!("fakehub storage failed to initialize in '{path}': {err}"); + panic!("fakehub storage failed to initialize in '{path}': {err}") } - }; + } } #[cfg(test)] @@ -52,7 +52,7 @@ mod tests { #[test] fn creates_xml_storage() { - touch_storage(); + touch_storage().unwrap(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); assert!( From 58a29ea135869de70257f48fb01a9c43238f1301 Mon Sep 17 00:00:00 2001 From: Aliaksei Bialiauski Date: Wed, 5 Jun 2024 14:33:56 +0300 Subject: [PATCH 13/17] feat(#9): option Co-authored-by: Ivan Ivanchuk --- src/xml/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index f811db12..ad9f7379 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -24,7 +24,7 @@ use std::fs::File; use log::info; -pub fn touch_storage() -> Result { +pub fn touch_storage(name: Option<&str>) -> Result { let path = "fakehub.xml"; info!("Initializing XML storage: {path}"); let creating = File::create(path); From ff60e25143e02b34e14b4468cada12c30b41b0f9 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 14:50:16 +0300 Subject: [PATCH 14/17] feat(#9): anyhow, no clean, option --- src/main.rs | 2 +- src/xml/storage.rs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 078b8a0c..784ba9d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use crate::xml::storage::touch_storage; #[tokio::main] async fn main() { - touch_storage().unwrap(); + touch_storage(Some("fakehub.xml")).unwrap(); let app = Router::new().route("/", get(home::home)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); diff --git a/src/xml/storage.rs b/src/xml/storage.rs index ad9f7379..3e33d9c1 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -25,7 +25,7 @@ use std::fs::File; use log::info; pub fn touch_storage(name: Option<&str>) -> Result { - let path = "fakehub.xml"; + let path = name.unwrap_or("fakehub.xml"); info!("Initializing XML storage: {path}"); let creating = File::create(path); match creating { @@ -41,24 +41,31 @@ pub fn touch_storage(name: Option<&str>) -> Result { #[cfg(test)] mod tests { - use std::fs; use std::path::Path; use crate::xml::storage::touch_storage; - fn clean() { - fs::remove_file("fakehub.xml").unwrap(); - } - #[test] - fn creates_xml_storage() { - touch_storage().unwrap(); + fn creates_xml_storage() -> anyhow::Result<()> { + touch_storage(None).unwrap(); let storage = "fakehub.xml"; let exists = Path::new(storage).exists(); assert!( exists, - "storage file '{storage}' was not created, but should" + "storage file '{storage}' was not created, but should be" + ); + Ok(()) + } + + #[test] + fn creates_xml_storage_with_different_name() -> anyhow::Result<()> { + let path = "test.xml"; + touch_storage(Some(path)).unwrap(); + let exists = Path::new(path).exists(); + assert!( + exists, + "storage file '{path}' was not created, but should be" ); - clean(); + Ok(()) } } From c160bcaf54ff733312720a682a889f702fa4facf Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 15:20:37 +0300 Subject: [PATCH 15/17] feat(#9): clean after assert --- src/xml/storage.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/xml/storage.rs b/src/xml/storage.rs index 3e33d9c1..c01f52be 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -41,6 +41,7 @@ pub fn touch_storage(name: Option<&str>) -> Result { #[cfg(test)] mod tests { + use std::fs; use std::path::Path; use crate::xml::storage::touch_storage; @@ -54,6 +55,7 @@ mod tests { exists, "storage file '{storage}' was not created, but should be" ); + fs::remove_file(storage).unwrap(); Ok(()) } @@ -66,6 +68,7 @@ mod tests { exists, "storage file '{path}' was not created, but should be" ); + fs::remove_file(path).unwrap(); Ok(()) } } From 0d3c5d517d85d2804fccf4561077a623355f4f13 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 5 Jun 2024 16:10:02 +0300 Subject: [PATCH 16/17] feat(#9): temp dir --- Cargo.toml | 7 ++++--- src/xml/storage.rs | 42 +++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 10f17bee..c23b6b20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,10 +33,11 @@ all. authors = ["Aliaksei BialĂ­auski ", "Ivanchuk Ivan "] [dependencies] -env_logger = "0.11.3" anyhow = "1.0.86" -log = { version = "0.4.21", features = [] } serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117" -axum = "0.7.5" tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "fs"] } +axum = "0.7.5" +log = { version = "0.4.21", features = [] } +env_logger = "0.11.3" +tempdir = "0.3.7" diff --git a/src/xml/storage.rs b/src/xml/storage.rs index c01f52be..742698a3 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -24,51 +24,51 @@ use std::fs::File; use log::info; -pub fn touch_storage(name: Option<&str>) -> Result { - let path = name.unwrap_or("fakehub.xml"); - info!("Initializing XML storage: {path}"); - let creating = File::create(path); - match creating { +pub fn touch_storage(path: Option<&str>) -> Result { + let location = path.unwrap_or("fakehub.xml"); + info!("Initializing XML storage: {location}"); + match File::create(location) { Ok(file) => { - info!("'{path}' initialized"); + info!("'{location}' initialized"); Ok(file) } Err(err) => { - panic!("fakehub storage failed to initialize in '{path}': {err}") + panic!("fakehub storage failed to initialize in '{location}': {err}") } } } #[cfg(test)] mod tests { - use std::fs; - use std::path::Path; + use tempdir::TempDir; use crate::xml::storage::touch_storage; #[test] fn creates_xml_storage() -> anyhow::Result<()> { - touch_storage(None).unwrap(); - let storage = "fakehub.xml"; - let exists = Path::new(storage).exists(); + let temp = TempDir::new("temp")?; + let path = temp.path().join("fakehub.xml"); + let storage = path.to_str(); + touch_storage(storage).unwrap(); assert!( - exists, - "storage file '{storage}' was not created, but should be" + path.exists(), + "storage file {:?} was not created, but should be", + storage ); - fs::remove_file(storage).unwrap(); Ok(()) } #[test] fn creates_xml_storage_with_different_name() -> anyhow::Result<()> { - let path = "test.xml"; - touch_storage(Some(path)).unwrap(); - let exists = Path::new(path).exists(); + let temp = TempDir::new("temp")?; + let path = temp.path().join("test.xml"); + let storage = path.to_str(); + touch_storage(storage).unwrap(); assert!( - exists, - "storage file '{path}' was not created, but should be" + path.exists(), + "storage file {:?} was not created, but should be", + storage ); - fs::remove_file(path).unwrap(); Ok(()) } } From 32b8822c5af0a1e174cfa7683c6f21bff845a0a0 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 5 Jun 2024 16:18:25 +0300 Subject: [PATCH 17/17] fix(touch_storage): remove overhead --- src/main.rs | 2 +- src/xml/storage.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 784ba9d3..50bb2df1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use crate::xml::storage::touch_storage; #[tokio::main] async fn main() { - touch_storage(Some("fakehub.xml")).unwrap(); + touch_storage(Some("fakehub.xml")); let app = Router::new().route("/", get(home::home)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); diff --git a/src/xml/storage.rs b/src/xml/storage.rs index 742698a3..1d7cff2f 100644 --- a/src/xml/storage.rs +++ b/src/xml/storage.rs @@ -19,18 +19,17 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use std::fmt::Error; use std::fs::File; use log::info; -pub fn touch_storage(path: Option<&str>) -> Result { +pub fn touch_storage(path: Option<&str>) -> File { let location = path.unwrap_or("fakehub.xml"); info!("Initializing XML storage: {location}"); match File::create(location) { Ok(file) => { info!("'{location}' initialized"); - Ok(file) + file } Err(err) => { panic!("fakehub storage failed to initialize in '{location}': {err}") @@ -49,7 +48,7 @@ mod tests { let temp = TempDir::new("temp")?; let path = temp.path().join("fakehub.xml"); let storage = path.to_str(); - touch_storage(storage).unwrap(); + touch_storage(storage); assert!( path.exists(), "storage file {:?} was not created, but should be", @@ -63,7 +62,7 @@ mod tests { let temp = TempDir::new("temp")?; let path = temp.path().join("test.xml"); let storage = path.to_str(); - touch_storage(storage).unwrap(); + touch_storage(storage); assert!( path.exists(), "storage file {:?} was not created, but should be",