-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make serde update as a standalone crate
- Loading branch information
Showing
6 changed files
with
102 additions
and
88 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 |
---|---|---|
@@ -1,16 +1,3 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"core", | ||
"primitives", | ||
"flare3d", | ||
# Utils | ||
"util/caches", | ||
"util/nbt_ext", | ||
"util/event", | ||
"util/edcode", | ||
"util/collections", | ||
"util/freezer", | ||
# Examples | ||
"flare3d/examples", | ||
] | ||
members = ["core", "primitives", "flare3d", "util/*", "flare3d/examples"] |
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
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,20 @@ | ||
[package] | ||
name = "rimecraft-serde-update" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["JieningYu <[email protected]>"] | ||
description = "Traits describing types that can be updated from a serialized representation" | ||
repository = "https://github.com/rimecraft-rs/rimecraft/" | ||
license = "AGPL-3.0-or-later" | ||
categories = ["data-structures"] | ||
|
||
[badges] | ||
maintenance = { status = "passively-maintained" } | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
erased-serde = { version = "0.4", optional = true } | ||
|
||
|
||
[features] | ||
erased = ["dep:erased-serde"] |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[cfg(feature = "erased")] | ||
pub mod erased; | ||
|
||
/// Represent types that are able to be updated | ||
/// through serializing and deserializing. | ||
pub trait Update: serde::Serialize { | ||
/// Update this type from a deserializer. | ||
fn update<'de, D>( | ||
&'de mut self, | ||
deserializer: D, | ||
) -> Result<(), <D as serde::Deserializer<'_>>::Error> | ||
where | ||
D: serde::Deserializer<'de>; | ||
} | ||
|
||
impl<T> Update for T | ||
where | ||
T: serde::Serialize + for<'de> serde::Deserialize<'de>, | ||
{ | ||
#[inline] | ||
fn update<'de, D>( | ||
&'de mut self, | ||
deserializer: D, | ||
) -> Result<(), <D as serde::Deserializer<'_>>::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
*self = Self::deserialize(deserializer)?; | ||
Ok(()) | ||
} | ||
} |