Correction of a genquery typo #44

Merged
Dandaedre merged 1 commits from weapons into project_weaponry 2025-02-17 21:31:16 +01:00
7 changed files with 51 additions and 55 deletions

View File

@ -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<T>(table: &str) -> Result<Vec<T>, crate::error::EquipementError> {
fn serialize_vec_from_table<T>(
table: &str,
) -> Result<Vec<T>, crate::error::FatalEquipementError> {
todo!()
}
fn serialize_vec_from_table_with_query<T>(
table: &str,
query: &str,
) -> Result<Vec<T>, crate::error::EquipementError> {
) -> Result<Vec<T>, crate::error::FatalEquipementError> {
todo!()
}
/// Checks if database exists, and returns a rusqlite::Connection. If not, opens database in memory.
fn new(filename: &str) -> Result<Self, EquipementError> {
fn new(filename: &str) -> Result<Self, FatalEquipementError> {
Ok(EquipementDatabase {
conn: Connection::open(filename)?,
})
}
fn initialize_empty_table<T>(table: &str) -> Result<(), crate::error::EquipementError> {
todo!()
}
}
/// Generate a SELECT query with fields generated from a struct. Returns a String

View File

@ -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),
}

View File

@ -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

View File

@ -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<Self, EquipementError>
fn new(origin: &str) -> Result<Self, FatalEquipementError>
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<T>(table: &str) -> std::result::Result<Vec<T>, EquipementError>;
fn serialize_vec_from_table<T>(
table: &str,
) -> std::result::Result<Vec<T>, FatalEquipementError>;
/// 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,
) -> std::result::Result<Vec<T>, EquipementError>;
) -> std::result::Result<Vec<T>, FatalEquipementError>;
/// Initialize an empty database & table
fn initialize_empty_table<T>(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<Self, EquipementError>
fn load_from_database() -> Result<Self, FatalEquipementError>
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

View File

@ -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

View File

@ -18,7 +18,7 @@ pub struct DatabaseMock {}
impl RecipeDatabase for DatabaseMock {
fn serialize_vec_from_table<T>(
table: &str,
) -> std::result::Result<Vec<T>, crate::error::EquipementError> {
) -> std::result::Result<Vec<T>, crate::error::FatalEquipementError> {
let _ = table;
todo!()
}
@ -26,19 +26,24 @@ impl RecipeDatabase for DatabaseMock {
fn serialize_vec_from_table_with_query<T>(
table: &str,
query: &str,
) -> std::result::Result<Vec<T>, crate::error::EquipementError> {
) -> std::result::Result<Vec<T>, crate::error::FatalEquipementError> {
let _ = table;
let _ = query;
todo!()
}
fn new(origin: &str) -> Result<Self, crate::error::EquipementError>
fn new(origin: &str) -> Result<Self, crate::error::FatalEquipementError>
where
Self: std::marker::Sized,
{
let _ = origin;
todo!()
}
fn initialize_empty_table<T>(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<Self, crate::error::EquipementError>
fn load_from_database() -> Result<Self, crate::error::FatalEquipementError>
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(())
}

View File

@ -14,3 +14,5 @@ fn export_to_tex() {}
/// Export the data generated to csv
fn export_to_csv() {}
// TODO: Consider deletion