Adds lifetimes, likely waste of time
This commit is contained in:
parent
91c5c4bb37
commit
701bb52a6c
|
|
@ -22,14 +22,14 @@ where
|
|||
for<'a> &'a <<Self as RecipeCollection>::Recipes as Combinable>::Inner: std::ops::Add,
|
||||
{
|
||||
/// The type of the inner recipes, this type must be combinable
|
||||
type Recipes: Combinable;
|
||||
type Recipes<'a>: Combinable<'a>;
|
||||
|
||||
/// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
|
||||
///
|
||||
/// This method doesn't make use of parallel iterators as the workload is way faster than would be the memory dispatch
|
||||
fn combine_all<G>(&mut self, other: &G)
|
||||
fn combine_all<'a, G>(&mut self, other: &G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes>,
|
||||
G: RecipeCollection<Recipes<'a> = Self::Recipes<'a>>,
|
||||
{
|
||||
self.assign_inner(
|
||||
self.ref_inner()
|
||||
|
|
@ -68,7 +68,7 @@ where
|
|||
/// Trait that ensure that two elements of a recipe are combinable,
|
||||
///
|
||||
/// Being combinable means it can be coerced into elements that implement add
|
||||
pub trait Combinable
|
||||
pub trait Combinable<'a>
|
||||
where
|
||||
for<'a> &'a <Self as Combinable>::Inner: std::ops::Add,
|
||||
{
|
||||
|
|
@ -102,13 +102,20 @@ where
|
|||
}
|
||||
|
||||
/// Type alias represinting the inner function parameter
|
||||
// #![feature(trait_alias)]
|
||||
pub(super) type FilterFunctionType<T> = dyn Fn(&T, &T) -> bool;
|
||||
/// Type alias representing a filter
|
||||
pub(super) type FilterType<T> = Box<Rc<FilterFunctionType<T>>>;
|
||||
pub(super) type FilterType<'a, T> = Box<Rc<&'a FilterFunctionType<T>>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
/// A generic Filtering function
|
||||
pub(crate) struct FilterFunction<T>(pub(super) FilterType<T>);
|
||||
pub(crate) struct FilterFunction<'a, T>(pub(super) FilterType<'a, T>);
|
||||
|
||||
// impl<T> FilterFunction<T> {
|
||||
// fn new_from_closure(m: &FilterFunctionType<T>) -> Self {
|
||||
// FilterFunction(Box::new(Rc::new(m.to_owned())))
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
|
||||
// ///
|
||||
|
|
|
|||
|
|
@ -8,16 +8,18 @@
|
|||
//! Implementations to transform all Specialized equipement into a generic Equipement
|
||||
//! A specific implementation could be preferable, but this simplicity might allow for easier developpement
|
||||
|
||||
use crate::interfaces::FilterFunction;
|
||||
use crate::interfaces::{FilterFunction, FilterType};
|
||||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::{
|
||||
Equipement,
|
||||
equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape},
|
||||
equipement_structs::{
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, default_filter_for_equipement,
|
||||
},
|
||||
};
|
||||
|
||||
impl From<EqShape> for Equipement {
|
||||
impl From<EqShape> for Equipement<'_> {
|
||||
fn from(val: EqShape) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
|
|
@ -25,7 +27,7 @@ impl From<EqShape> for Equipement {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<EqMaterial> for Equipement {
|
||||
impl From<EqMaterial> for Equipement<'_> {
|
||||
fn from(val: EqMaterial) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
|
|
@ -33,15 +35,15 @@ impl From<EqMaterial> for Equipement {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<EqNature> for Equipement {
|
||||
impl From<EqNature> for Equipement<'_> {
|
||||
fn from(val: EqNature) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
..Default::default()
|
||||
filter_function: FilterFunction(default_filter_for_equipement()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<EqFinishing> for Equipement {
|
||||
impl From<EqFinishing> for Equipement<'_> {
|
||||
fn from(val: EqFinishing) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
|
|
@ -50,7 +52,7 @@ impl From<EqFinishing> for Equipement {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for FilterFunction<T> {
|
||||
impl<T> Debug for FilterFunction<'_, T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
|
@ -60,12 +62,12 @@ impl<T> Debug for FilterFunction<T> {
|
|||
)
|
||||
}
|
||||
}
|
||||
impl<T> Default for FilterFunction<T> {
|
||||
impl<T> Default for FilterFunction<'_, T> {
|
||||
fn default() -> Self {
|
||||
FilterFunction(Box::new(Rc::new(|_, _| true)))
|
||||
FilterFunction(Box::new(Rc::new(&|_, _| true)))
|
||||
}
|
||||
}
|
||||
impl<T> PartialEq for FilterFunction<T> {
|
||||
impl<T> PartialEq for FilterFunction<'_, T> {
|
||||
fn eq(&self, _other: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::interfaces::{Combinable, RecipeCollection};
|
|||
|
||||
use super::{Equipement, FinalEquipementList, equipement_structs::InnerStats};
|
||||
|
||||
impl Combinable for Equipement {
|
||||
impl Combinable for Equipement<'_> {
|
||||
type Inner = InnerStats;
|
||||
|
||||
fn combinable_part(&self) -> &Self::Inner {
|
||||
|
|
@ -31,8 +31,8 @@ impl Combinable for Equipement {
|
|||
}
|
||||
}
|
||||
|
||||
impl RecipeCollection for FinalEquipementList {
|
||||
type Recipes = Equipement;
|
||||
impl RecipeCollection for FinalEquipementList<'_> {
|
||||
type Recipes<'a> = Equipement<'a>;
|
||||
|
||||
fn from_vectored(list: Vec<Self::Recipes>) -> Self {
|
||||
Self { inner: list }
|
||||
|
|
@ -174,7 +174,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_basic_logic() {}
|
||||
|
||||
impl Equipement {
|
||||
impl Equipement<'_> {
|
||||
fn newish(name: &[&str], i: u8) -> Self {
|
||||
Equipement {
|
||||
stats: InnerStats {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use std::rc::Rc;
|
|||
|
||||
use struct_field_names_as_array::FieldNamesAsArray;
|
||||
|
||||
use crate::interfaces::FilterFunction;
|
||||
use crate::interfaces::{FilterFunction, FilterType};
|
||||
|
||||
use super::{DamageType, NatureTarget, SpecialCategory, WeaponCategory};
|
||||
|
||||
|
|
@ -15,32 +15,37 @@ use super::{DamageType, NatureTarget, SpecialCategory, WeaponCategory};
|
|||
/// This list is initialized with the base part and updated by succesive combinaisons
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct FinalEquipementList {
|
||||
pub struct FinalEquipementList<'a> {
|
||||
/// Inner List of final equipements
|
||||
pub(super) inner: Vec<Equipement>,
|
||||
pub(super) inner: Vec<Equipement<'a>>,
|
||||
}
|
||||
|
||||
/// The final equipement, obtained by combining all parts
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct Equipement {
|
||||
pub struct Equipement<'a> {
|
||||
/// The inner stats used by the equipement
|
||||
pub(super) stats: InnerStats,
|
||||
/// The filter, used to determine if adding is warranted
|
||||
pub(super) filter_function: FilterFunction<InnerStats>,
|
||||
pub(super) filter_function: FilterFunction<'a, InnerStats>,
|
||||
}
|
||||
|
||||
impl Default for Equipement {
|
||||
impl Default for Equipement<'_> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
filter_function: FilterFunction(Box::new(Rc::new(|self_, lhs| {
|
||||
!self_.id.iter().any(|a| *a == lhs.id[0])
|
||||
}))),
|
||||
filter_function: FilterFunction(default_filter_for_equipement()),
|
||||
stats: InnerStats::random_new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The default filter function used by the equipements
|
||||
pub(super) fn default_filter_for_equipement() -> FilterType<'static, InnerStats> {
|
||||
Box::new(Rc::new(&|self_, lhs| {
|
||||
!self_.id.iter().any(|a| *a == lhs.id[0])
|
||||
}))
|
||||
}
|
||||
|
||||
/// The inner statistics of the equipement, used across all parts and final weapon
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone, Default, FieldNamesAsArray, Debug)]
|
||||
|
|
@ -104,8 +109,6 @@ pub struct EqMaterial {
|
|||
pub struct EqNature {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
// TODO: Be sure to take this into account
|
||||
#[allow(dead_code)]
|
||||
/// Which kind of target this nature applies to
|
||||
pub(super) target: NatureTarget,
|
||||
}
|
||||
|
|
@ -128,7 +131,7 @@ mod test {
|
|||
|
||||
// use pretty_assertions::assert_eq;
|
||||
|
||||
fn list_equip() -> Vec<Equipement> {
|
||||
fn list_equip() -> Vec<Equipement<'static>> {
|
||||
(0..10)
|
||||
.map(|_| Equipement {
|
||||
..Default::default()
|
||||
|
|
|
|||
Loading…
Reference in New Issue