-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Handle Serialization and Deserialization #2306
Changes from 1 commit
1ac0833
3e09b8c
2d8f849
2c4ce2e
e71c300
bc96a93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,31 +75,14 @@ impl<'de, T: Asset> Deserialize<'de> for Handle<T> { | |
} | ||
|
||
impl AssetServer { | ||
pub fn serialize_with_asset_refs<S, T>( | ||
&self, | ||
serializer: S, | ||
value: &T, | ||
) -> Result<S::Ok, S::Error> | ||
/// Enables asset references to be serialized or deserialized | ||
pub fn with_asset_refs_serialization<F, T>(&self, f: F) -> T | ||
where | ||
S: Serializer, | ||
T: Serialize, | ||
{ | ||
ASSET_SERVER.with(|key| { | ||
key.replace(Some(self.clone())); | ||
let result = value.serialize(serializer); | ||
key.replace(None); | ||
result | ||
}) | ||
} | ||
|
||
pub fn deserialize_with_asset_refs<'de, D, T>(&self, deserializer: D) -> Result<T, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
T: Deserialize<'de>, | ||
F: FnOnce() -> T, | ||
{ | ||
ASSET_SERVER.with(|key| { | ||
key.replace(Some(self.clone())); | ||
let result = T::deserialize(deserializer); | ||
let result = (f)(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have an example use case of how this API is better than the previous one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the last API didn't allow to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that makes sense. |
||
key.replace(None); | ||
result | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you give
f
a more descriptive name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f
,func
are commonly used in this situations, anything in mind?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
serde_func
(that expresses the functions does some sort of (de)serialization) would be nice.