diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index a1d1ffc..92126cf 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -150,13 +150,6 @@ pub trait ToCSV { fn write_csv(&self, path: &Path) -> csv::Result<()>; } -/// Garanties that a struct can be generated from a database -#[deprecated] -pub trait DbSerializable { - /// Serialize the object from a database - fn from_database() -> Self; -} - /// A generic database+connection, handling all the deserialization of the inner types pub trait RecipeDatabase { /// Create the database from a file @@ -177,19 +170,25 @@ pub trait RecipeDatabase { &self, table: &str, ) -> Result<(), FatalEquipementError>; + + /// Insert a row inside the database, while mostly unused this function is needed to initialize the empty table with an empty row if needed + fn insert_row(&self, row: T) -> Result<(), FatalEquipementError>; } /// Trait implemented by any struct aiming to be a public recipe pub trait FixedRecipe { - /// Struct representing the database type, most likely a string - type Database; + // /// Struct representing the database type, most likely a string + // type Database; /// Struct representing the keylist type, most likely a usize - type KeyList; + type KeyList; // TODO: Add the restriction &traits to use the result afterwards /// Get the list of elements corresponding to the recipe /// /// These elements will either be iteratively fetched from the database or scoured through in the data depending on the scenario - fn get_elements() -> Vec<(Self::Database, Self::KeyList)>; + fn get_elements_from_table( + &self, + table: &str, + ) -> Result, FatalEquipementError>; } /// Trait ensuring a status report can be inferred from the structure diff --git a/weaponry/src/weaponry_structs/equipement_fields.rs b/weaponry/src/weaponry_structs/equipement_fields.rs index af2ebe1..e1d9e1b 100644 --- a/weaponry/src/weaponry_structs/equipement_fields.rs +++ b/weaponry/src/weaponry_structs/equipement_fields.rs @@ -54,15 +54,6 @@ pub enum DamageMod { // TODO: avoid pub make an impl ? pub struct DamageType(pub Vec); -// TODO: Find a better way to make an easy creation at least for tests -impl From<&str> for DamageType { - fn from(value: &str) -> Self { - let _ = value; - // Split by , then recurse from and collect - todo!() - } -} - impl Display for DamageType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 26659fd..47afd3f 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -8,7 +8,7 @@ use crate::database::{generate_create_table_query, get_data}; use crate::error::FatalEquipementError; -use crate::interfaces::RecipeDatabase; +use crate::interfaces::{FixedRecipe, RecipeDatabase}; use rusqlite::Connection; use serde::de::DeserializeOwned; @@ -47,6 +47,30 @@ impl RecipeDatabase for EquipementDatabase { .execute(generate_create_table_query(table, attr_map).as_str(), ())?; Ok(()) } + + fn insert_row(&self, row: T) -> Result<(), FatalEquipementError> { + let _ = row; + todo!() + } +} +#[allow(missing_docs)] +pub struct EquipementFixedRecipe { + pub conn: rusqlite::Connection, +} + +#[allow(missing_docs)] +pub struct MockRecipe {} + +impl FixedRecipe for EquipementFixedRecipe { + type KeyList = MockRecipe; + + fn get_elements_from_table( + &self, + table: &str, + ) -> Result, FatalEquipementError> { + let _ = table; + todo!() + } } // #[allow(clippy::useless_conversion)] diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index 1d7f81e..5670c0f 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -45,6 +45,14 @@ impl RecipeDatabase for DatabaseMock { let _ = table; unimplemented!() } + + fn insert_row( + &self, + row: T, + ) -> Result<(), FatalEquipementError> { + let _ = row; + todo!() + } } /// Mock config pub struct ConfigMock {}