79 lines
2.2 KiB
Rust
79 lines
2.2 KiB
Rust
// Workspace: weaponry
|
|
// File: weaponry/src/weaponry_structs/equipement_into_impls.rs
|
|
// TODO: At some point a trait might want to be used to use these into instead of calling it directly
|
|
// : Doing so would ensure all prerequists are met
|
|
// : Another way of doing so might be to instead use Into<Combinable> instead
|
|
// : Another way would be to add a filter field that would allow or not the combinaison and abstract all
|
|
// logic that would be into doing multi traits things
|
|
//! 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 std::fmt::Debug;
|
|
use std::rc::Rc;
|
|
|
|
use super::{
|
|
Equipement,
|
|
equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape},
|
|
};
|
|
|
|
impl From<EqShape> for Equipement {
|
|
fn from(val: EqShape) -> Self {
|
|
Self {
|
|
stats: val.stats,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
impl From<EqMaterial> for Equipement {
|
|
fn from(val: EqMaterial) -> Self {
|
|
Self {
|
|
stats: val.stats,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
impl From<EqNature> for Equipement {
|
|
fn from(val: EqNature) -> Self {
|
|
Self {
|
|
stats: val.stats,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
impl From<EqFinishing> for Equipement {
|
|
fn from(val: EqFinishing) -> Self {
|
|
Self {
|
|
stats: val.stats,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T> Debug for FilterFunction<T> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"Filter:{}",
|
|
// std::any::type_name::<T>(),
|
|
std::any::type_name::<Self>()
|
|
)
|
|
}
|
|
}
|
|
impl<T> Default for FilterFunction<T> {
|
|
fn default() -> Self {
|
|
FilterFunction(Box::new(Rc::new(|_, _| true)))
|
|
}
|
|
}
|
|
impl<T> PartialEq for FilterFunction<T> {
|
|
fn eq(&self, _other: &Self) -> bool {
|
|
true
|
|
}
|
|
}
|
|
// impl<T> FilterFunction<T> {
|
|
// /// Generate a new filter
|
|
// pub fn new(filter: FilterFunctionType<T>) -> Self {
|
|
// Self(Box::new(Rc::new(filter)))
|
|
// }
|
|
// }
|