Skip to content

Commit

Permalink
serde_userdata: Remove map_err to reduce compile time impact (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-nie authored Aug 21, 2024
1 parent c58f67b commit 26b9bdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `Lua::replace_registry_value` takes `&mut RegistryKey`
- `Lua::scope` temporary disabled (will be re-added in the next release)
- Reduced the compile time contribution of `next_key_seed` and `next_value_seed`.
- Reduced the compile time contribution of `serde_userdata`.

## v0.9.9

Expand Down
9 changes: 7 additions & 2 deletions src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ fn serde_userdata<V>(
ud: AnyUserData,
f: impl FnOnce(serde_value::Value) -> std::result::Result<V, serde_value::DeserializerError>,
) -> Result<V> {
let value = serde_value::to_value(ud).map_err(|err| Error::SerializeError(err.to_string()))?;
f(value).map_err(|err| Error::DeserializeError(err.to_string()))
match serde_value::to_value(ud) {
Ok(value) => match f(value) {
Ok(r) => Ok(r),
Err(error) => Err(Error::DeserializeError(error.to_string())),
},
Err(error) => Err(Error::SerializeError(error.to_string())),
}
}

0 comments on commit 26b9bdb

Please sign in to comment.