From a0b0012d76c6c50af6ae8e97546c87e5f631cf75 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 17 Feb 2025 21:30:46 +0100 Subject: [PATCH] Correction of a genquery typo --- weaponry/src/database.rs | 14 +++++--- weaponry/src/error.rs | 34 +++++++++---------- weaponry/src/export.rs | 1 + weaponry/src/interfaces.rs | 17 ++++++---- .../equipement_impl_database.rs | 23 +------------ .../weaponry_structs/equipement_scenario.rs | 15 +++++--- .../src/weaponry_structs/equipement_tools.rs | 2 ++ 7 files changed, 51 insertions(+), 55 deletions(-) diff --git a/weaponry/src/database.rs b/weaponry/src/database.rs index 04c0dd7..5404d6a 100644 --- a/weaponry/src/database.rs +++ b/weaponry/src/database.rs @@ -5,7 +5,7 @@ //! Should dump whole database in a vec of structs from weaponry_structs #![allow(dead_code)] -use crate::{error::EquipementError, interfaces::RecipeDatabase}; +use crate::{error::FatalEquipementError, interfaces::RecipeDatabase}; use rusqlite::{self, Connection}; use serde::de::DeserializeOwned; @@ -33,23 +33,29 @@ impl EquipementDatabase { } impl RecipeDatabase for EquipementDatabase { - fn serialize_vec_from_table(table: &str) -> Result, crate::error::EquipementError> { + fn serialize_vec_from_table( + table: &str, + ) -> Result, crate::error::FatalEquipementError> { todo!() } fn serialize_vec_from_table_with_query( table: &str, query: &str, - ) -> Result, crate::error::EquipementError> { + ) -> Result, crate::error::FatalEquipementError> { todo!() } /// Checks if database exists, and returns a rusqlite::Connection. If not, opens database in memory. - fn new(filename: &str) -> Result { + fn new(filename: &str) -> Result { Ok(EquipementDatabase { conn: Connection::open(filename)?, }) } + + fn initialize_empty_table(table: &str) -> Result<(), crate::error::EquipementError> { + todo!() + } } /// Generate a SELECT query with fields generated from a struct. Returns a String diff --git a/weaponry/src/error.rs b/weaponry/src/error.rs index fda0aa6..9465967 100644 --- a/weaponry/src/error.rs +++ b/weaponry/src/error.rs @@ -5,29 +5,27 @@ use thiserror::Error; -// #[derive(Error, Debug)] -// /// Unrecoverable Error, all these error cannot gracefully fail and must return to the User for further handling -// pub enum FatalEquipementError { -// #[error("Rusqlite failed to connect to the given path {0}")] -// RusqliteConnection(#[from] rusqlite::Error), -// } +#[derive(Error, Debug)] +/// Unrecoverable Error, all these error cannot gracefully fail and must return to the User for further handling +pub enum FatalEquipementError { + #[error("Rusqlite failed to connect to the given path {0}")] + RusqliteConnection(#[from] rusqlite::Error), +} -// #[derive(Error, Debug)] -// /// Recoverable error, all these error exist to signal a retry or another path that should be taken by the program -// pub enum TrivialEquipementError { -// #[error("Very simple error")] -// Oops, -// } +#[derive(Error, Debug)] +/// Recoverable error, all these error exist to signal a retry or another path that should be taken by the program +pub enum LocalEquipementError { + #[error("Very simple error")] + Oops, +} #[derive(Error, Debug)] /// An equipement error, either unrecoverable, indicating a that the execution /// flow must be stopped and only an user input can solve the issue pub enum EquipementError { - // #[error("An unrecoverable error occured: {0}")] - // Unrecoverable(#[from] FatalEquipementError), + #[error("An unrecoverable error occured: {0}")] + Fatal(#[from] FatalEquipementError), - // #[error("A recoverable error occured but wasn't caught by the programming: {0}")] - // Recoverable(#[from] TrivialEquipementError), - #[error("Rusqlite failed to connect to the given path {0}")] - RusqliteConnection(#[from] rusqlite::Error), + #[error("A local error occured an wasn't recovered from: {0}")] + Local(#[from] LocalEquipementError), } diff --git a/weaponry/src/export.rs b/weaponry/src/export.rs index 03cffb7..8b93802 100644 --- a/weaponry/src/export.rs +++ b/weaponry/src/export.rs @@ -1,3 +1,4 @@ // Workspace: weaponry // File: weaponry/src/export.rs //! Export module in charge of transforming data structure into their tex counterpart through the appropriate traits +// TODO: Consider deletion diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index 0de0c51..1895c6d 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -7,7 +7,7 @@ use std::{path::Path, rc::Rc}; -use crate::error::EquipementError; +use crate::error::{EquipementError, FatalEquipementError}; /// Trait representing a view table /// @@ -157,18 +157,23 @@ pub trait DbSerializable { /// A generic database+connection, handling all the deserialization of the inner types pub trait RecipeDatabase { /// Create the database from a file - fn new(origin: &str) -> Result + fn new(origin: &str) -> Result where Self: std::marker::Sized; /// Serialize a vector of objects of the given type in the specified table of the underlying database - fn serialize_vec_from_table(table: &str) -> std::result::Result, EquipementError>; + fn serialize_vec_from_table( + table: &str, + ) -> std::result::Result, FatalEquipementError>; /// Serialize a specified vector of objects of the given type with an additionnal restriction fn serialize_vec_from_table_with_query( table: &str, query: &str, - ) -> std::result::Result, EquipementError>; + ) -> std::result::Result, FatalEquipementError>; + + /// Initialize an empty database & table + fn initialize_empty_table(table: &str) -> Result<(), EquipementError>; } /// Trait implemented by any struct aiming to be a public recipe @@ -207,12 +212,12 @@ pub trait Scenario { type Config; /// Load all database into intermediate representation - fn load_from_database() -> Result + fn load_from_database() -> Result where Self: std::marker::Sized; /// Configure the scenario to the user's needs - fn configure_scenario(&mut self, config: Self::Config) -> Result<(), EquipementError>; + fn configure_scenario(&mut self, config: Self::Config) -> Result<(), FatalEquipementError>; // All these steps should be implemented but not required // enforcing them helps writing new impls more easily but is not really nice in any way diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 271decd..5e60565 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -6,25 +6,4 @@ // use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape}; -// //TODO: Fred, make these and I'm happy - -// impl DbSerializable for EqShape { -// fn from_database() -> Self { -// todo!() -// } -// } -// impl DbSerializable for EqMaterial { -// fn from_database() -> Self { -// todo!() -// } -// } -// impl DbSerializable for EqNature { -// fn from_database() -> Self { -// todo!() -// } -// } -// impl DbSerializable for EqFinishing { -// fn from_database() -> Self { -// todo!() -// } -// } +// TODO: Migrate from database to here diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index 06b6f55..2998561 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -18,7 +18,7 @@ pub struct DatabaseMock {} impl RecipeDatabase for DatabaseMock { fn serialize_vec_from_table( table: &str, - ) -> std::result::Result, crate::error::EquipementError> { + ) -> std::result::Result, crate::error::FatalEquipementError> { let _ = table; todo!() } @@ -26,19 +26,24 @@ impl RecipeDatabase for DatabaseMock { fn serialize_vec_from_table_with_query( table: &str, query: &str, - ) -> std::result::Result, crate::error::EquipementError> { + ) -> std::result::Result, crate::error::FatalEquipementError> { let _ = table; let _ = query; todo!() } - fn new(origin: &str) -> Result + fn new(origin: &str) -> Result where Self: std::marker::Sized, { let _ = origin; todo!() } + + fn initialize_empty_table(table: &str) -> Result<(), crate::error::EquipementError> { + let _ = table; + todo!() + } } /// Mock config pub struct ConfigMock {} @@ -70,7 +75,7 @@ impl Scenario for CrossRecipeScenario { type FinalListType = RefinedEquipementList; type Config = ConfigMock; - fn load_from_database() -> Result + fn load_from_database() -> Result where Self: std::marker::Sized, { @@ -80,7 +85,7 @@ impl Scenario for CrossRecipeScenario { fn configure_scenario( &mut self, config: Self::Config, - ) -> Result<(), crate::error::EquipementError> { + ) -> Result<(), crate::error::FatalEquipementError> { self.config = config; Ok(()) } diff --git a/weaponry/src/weaponry_structs/equipement_tools.rs b/weaponry/src/weaponry_structs/equipement_tools.rs index 739aad5..fe2c698 100644 --- a/weaponry/src/weaponry_structs/equipement_tools.rs +++ b/weaponry/src/weaponry_structs/equipement_tools.rs @@ -14,3 +14,5 @@ fn export_to_tex() {} /// Export the data generated to csv fn export_to_csv() {} + +// TODO: Consider deletion -- 2.45.1