From 32b8822c5af0a1e174cfa7683c6f21bff845a0a0 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 5 Jun 2024 16:18:25 +0300 Subject: [PATCH] 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",