Add basic database implementation and some Scenario skeleton #42
|
|
@ -20,13 +20,13 @@ pub trait ViewTable {
|
|||
/// The inner type of element that one would be peeking into
|
||||
///
|
||||
/// Usually the final representation of an Item
|
||||
type InterestElement: RefinedList;
|
||||
type InterestElementList: RefinedList;
|
||||
|
||||
/// Give a list of interesting element indicises to further analyse
|
||||
fn index_of_interest_points(&self) -> Vec<usize>;
|
||||
|
||||
/// Interrogate the FinalRepresentation to find interesting elements
|
||||
fn find_points_of_interest(&self, representation: &Self::InterestElement);
|
||||
fn find_points_of_interest(&self, representation: &Self::InterestElementList);
|
||||
// An alternative, non Self::Typed way of doing since there is only one usage for now
|
||||
// fn find_points_of_interest(&self, representation: &impl FinalRepresentation);
|
||||
}
|
||||
|
|
@ -148,13 +148,26 @@ pub trait ToCSV {
|
|||
}
|
||||
|
||||
/// 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 {
|
||||
/// Serialize a vector of objects of the given type in the specified table of the underlying database
|
||||
fn serialize_vec_from_table<T>(table: &str) -> Result<T, EquipementError>;
|
||||
|
||||
/// Serialize a specified vector of objects of the given type with an additionnal restriction
|
||||
fn serialize_vec_from_table_with_query<T>(
|
||||
table: &str,
|
||||
query: &str,
|
||||
) -> Result<T, EquipementError>;
|
||||
}
|
||||
|
||||
/// Trait implemented by any struct aiming to be a public recipe
|
||||
pub trait FixedRecipe: DbSerializable {
|
||||
pub trait FixedRecipe {
|
||||
/// Struct representing the database type, most likely a string
|
||||
type Database;
|
||||
/// Struct representing the keylist type, most likely a usize
|
||||
|
|
@ -179,18 +192,23 @@ pub trait Reportable {
|
|||
/// The inner working while somehow abstracted are very tied together and tied to the impl
|
||||
pub trait Scenario {
|
||||
/// The inner database type
|
||||
type DatabaseType; //: Database;
|
||||
type DatabaseType: RecipeDatabase;
|
||||
/// The type of viewtable that must be returned by the scenario
|
||||
// Could also use dyn dispatch but since all of it is so tied down...
|
||||
type ViewTableType: ViewTable;
|
||||
/// The type of the final recipe list
|
||||
type FinalListType: RefinedList;
|
||||
/// Inner configuration
|
||||
type Config;
|
||||
|
||||
/// Load all database into intermediate representation
|
||||
fn load_from_database() -> Result<Self, EquipementError>
|
||||
where
|
||||
Self: std::marker::Sized;
|
||||
|
||||
/// Configure the scenario to the user's needs
|
||||
fn configure_scenario(&mut self, config: Self::Config) -> Result<(), EquipementError>;
|
||||
|
||||
// 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
|
||||
//
|
||||
|
|
|
|||
|
|
@ -2,29 +2,29 @@
|
|||
// File: weaponry/src/weaponry_structs/equipement_impl_database.rs
|
||||
//! All database specific implementations
|
||||
|
||||
use crate::interfaces::DbSerializable;
|
||||
// use crate::interfaces::DbSerializable;
|
||||
|
||||
use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape};
|
||||
// use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape};
|
||||
|
||||
//TODO: Fred, make these and I'm happy
|
||||
// //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!()
|
||||
}
|
||||
}
|
||||
// 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!()
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_scenario.rs
|
||||
//! Implementations of a full scenario,
|
||||
//!
|
||||
//! These implementation must take care of everything from database retrieval to view exporting,
|
||||
//! however all they mostly do is glue together all the parts designed in the interface,
|
||||
//! and therefore mostly serves as a TO-DO list
|
||||
//!
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::interfaces::{RecipeDatabase, Scenario, ViewTable};
|
||||
|
||||
use super::equipement_advanced_repr::RefinedEquipementList;
|
||||
|
||||
/// Mock of the existing database
|
||||
pub struct DatabaseMock {}
|
||||
impl RecipeDatabase for DatabaseMock {
|
||||
fn serialize_vec_from_table<T>(table: &str) -> Result<T, crate::error::EquipementError> {
|
||||
let _ = table;
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn serialize_vec_from_table_with_query<T>(
|
||||
table: &str,
|
||||
query: &str,
|
||||
) -> Result<T, crate::error::EquipementError> {
|
||||
let _ = table;
|
||||
let _ = query;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
/// Mock config
|
||||
pub struct ConfigMock {}
|
||||
/// Mock Viewtable
|
||||
pub struct ViewtableMock {}
|
||||
impl ViewTable for ViewtableMock {
|
||||
type InterestElementList = RefinedEquipementList;
|
||||
|
||||
fn index_of_interest_points(&self) -> Vec<usize> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn find_points_of_interest(&self, representation: &Self::InterestElementList) {
|
||||
let _ = representation;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// A simple cross recipe scenario
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
pub struct CrossRecipeScenario {
|
||||
database: DatabaseMock,
|
||||
config: ConfigMock,
|
||||
}
|
||||
|
||||
impl Scenario for CrossRecipeScenario {
|
||||
type DatabaseType = DatabaseMock;
|
||||
type ViewTableType = ViewtableMock;
|
||||
type FinalListType = RefinedEquipementList;
|
||||
type Config = ConfigMock;
|
||||
|
||||
fn load_from_database() -> Result<Self, crate::error::EquipementError>
|
||||
where
|
||||
Self: std::marker::Sized,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn configure_scenario(
|
||||
&mut self,
|
||||
config: Self::Config,
|
||||
) -> Result<(), crate::error::EquipementError> {
|
||||
self.config = config;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_refined_recipes(&self) -> Self::FinalListType {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn generate_view_tables(&self) -> Self::ViewTableType {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
@ -15,13 +15,13 @@ use super::equipement_advanced_repr::RefinedEquipementList;
|
|||
struct EquipementFullView {}
|
||||
|
||||
impl ViewTable for EquipementFullView {
|
||||
type InterestElement = RefinedEquipementList;
|
||||
type InterestElementList = RefinedEquipementList;
|
||||
|
||||
fn index_of_interest_points(&self) -> Vec<usize> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn find_points_of_interest(&self, representation: &Self::InterestElement) {
|
||||
fn find_points_of_interest(&self, representation: &Self::InterestElementList) {
|
||||
let _ = representation;
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ mod equipement_impl_database;
|
|||
mod equipement_impl_io;
|
||||
mod equipement_impl_logic;
|
||||
mod equipement_impl_math;
|
||||
mod equipement_scenario;
|
||||
pub mod equipement_structs;
|
||||
pub mod equipement_tools;
|
||||
mod equipement_views;
|
||||
|
|
|
|||
Loading…
Reference in New Issue