-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Convert<Option<TypeTagged>>
and Convert<Vec<TypeTagged>>
#1
Comments
I think these are entirely possible to be created by the user. |
The new https://github.com/mintlu8/bevy_serde_project/releases/tag/0.2.0 |
Thank you, but how do they work with TypeTagged? I'm curious! These are failed #[serde_project("ProjectVec<Vec<TypeTagged<Box<dyn DualAxisProcessor>>>>")]
pub(crate) sequence: Vec<Box<dyn DualAxisProcessor>>,
#[serde_project("ProjectVec<Vec<Box<dyn DualAxisProcessor>>>")]
pub(crate) sequence: Vec<Box<dyn DualAxisProcessor>>, |
The first field should be an exact copy of the Vec's type, the second field (optional) should be the projection of individual fields. ProjectVec<Vec<Box<dyn DualAxisProcessor>>, TypeTagged<Box<dyn DualAxisProcessor>>>" |
Yeah, that fixes the issue. But it seems like I'm running into another problem with recursive dyn Traits. It looks like #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize, SerdeProject)]
pub struct DualAxisProcessingPipeline {
#[serde_project(
"ProjectVec<Vec<Box<dyn DualAxisProcessor>>, TypeTagged<Box<dyn DualAxisProcessor>>>"
)]
pub(crate) sequence: Vec<Box<dyn DualAxisProcessor>>,
}
impl DualAxisProcessor for DualAxisProcessingPipeline {
/// Computes the result by passing the `input_value` through this pipeline.
#[must_use]
#[inline]
fn process(&self, input_value: Vec2) -> Vec2 {
self.sequence
.iter()
.fold(input_value, |value, next| next.process(value))
}
#[doc(hidden)]
fn typetag_name(&self) -> &'static str {
"DualAxisProcessingPipeline"
}
#[doc(hidden)]
fn as_ser(&self) -> &dyn bevy::reflect::erased_serde::Serialize {
self
}
}
impl IntoTypeTagged<Box<dyn DualAxisProcessor>> for DualAxisProcessingPipeline {
fn name() -> impl AsRef<str> {
"DualAxisProcessingPipeline"
}
fn into_type_tagged(self) -> Box<dyn DualAxisProcessor> {
Box::new(self)
}
} But no worries, it seems that bevy_serde_project primarily focuses on serializing and deserializing Components and Resources, rather than their internal fields. If the approach is too tricky, I'm also exploring an alternative solution using serde_tagged |
All Closing this since the issue is solved. |
Would it be possible to add these Converters? I would really appreciate it. They are essential for
The text was updated successfully, but these errors were encountered: