-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support conversion of ints and strings directly into hash
- Loading branch information
Showing
3 changed files
with
79 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::{Hash, ParamList2, ParamStruct2, ParamType}; | ||
|
||
/// A fake clone implementation. PyO3 uses blanket implementations of FromPyObject for pyclasses | ||
/// when they implement Clone. I need to have custom implementations for some types | ||
pub(crate) trait Duplicate: Sized { | ||
fn duplicate(&self) -> Self; | ||
} | ||
|
||
impl<T> Duplicate for T | ||
where | ||
T: Clone, | ||
{ | ||
fn duplicate(&self) -> Self { | ||
self.clone() | ||
} | ||
} | ||
|
||
impl Duplicate for ParamType { | ||
fn duplicate(&self) -> Self { | ||
match self { | ||
ParamType::Bool(v) => ParamType::Bool(*v), | ||
ParamType::I8(v) => ParamType::I8(*v), | ||
ParamType::U8(v) => ParamType::U8(*v), | ||
ParamType::I16(v) => ParamType::I16(*v), | ||
ParamType::U16(v) => ParamType::U16(*v), | ||
ParamType::I32(v) => ParamType::I32(*v), | ||
ParamType::U32(v) => ParamType::U32(*v), | ||
ParamType::Float(v) => ParamType::Float(*v), | ||
ParamType::Hash(v) => ParamType::Hash(v.duplicate()), | ||
ParamType::Str(v) => ParamType::Str(v.clone()), | ||
ParamType::List(v) => ParamType::List(v.duplicate()), | ||
ParamType::Struct(v) => ParamType::Struct(v.duplicate()), | ||
} | ||
} | ||
} | ||
|
||
impl Duplicate for Hash { | ||
fn duplicate(&self) -> Self { | ||
Hash { inner: self.inner } | ||
} | ||
} | ||
|
||
impl Duplicate for ParamList2 { | ||
fn duplicate(&self) -> Self { | ||
ParamList2(self.0.duplicate()) | ||
} | ||
} | ||
|
||
impl Duplicate for ParamStruct2 { | ||
fn duplicate(&self) -> Self { | ||
ParamStruct2( | ||
self.0 | ||
.iter() | ||
.map(|(h, p)| (h.duplicate(), p.duplicate())) | ||
.collect(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,3 @@ | |
fighter[key].value = fighter_mods[key] | ||
|
||
fighter_param.save("fighter_param_new.prc") | ||
|