Adds a mock implementation of fixed recipes #50
|
|
@ -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<T: DeserializeOwned>(&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<Vec<Self::KeyList>, FatalEquipementError>;
|
||||
}
|
||||
|
||||
/// Trait ensuring a status report can be inferred from the structure
|
||||
|
|
|
|||
|
|
@ -54,15 +54,6 @@ pub enum DamageMod {
|
|||
// TODO: avoid pub make an impl ?
|
||||
pub struct DamageType(pub Vec<DamageMod>);
|
||||
|
||||
// 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!(
|
||||
|
|
|
|||
|
|
@ -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<T: DeserializeOwned>(&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<Vec<Self::KeyList>, FatalEquipementError> {
|
||||
let _ = table;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// #[allow(clippy::useless_conversion)]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,14 @@ impl RecipeDatabase for DatabaseMock {
|
|||
let _ = table;
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn insert_row<T: serde::de::DeserializeOwned>(
|
||||
&self,
|
||||
row: T,
|
||||
) -> Result<(), FatalEquipementError> {
|
||||
let _ = row;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
/// Mock config
|
||||
pub struct ConfigMock {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue