serde_userdata: Remove map_err to reduce compile time impact (#441)

This commit is contained in:
Sven Niederberger
2024-08-21 13:06:49 +02:00
committed by GitHub
parent c58f67b140
commit 26b9bdb362
2 changed files with 8 additions and 2 deletions
+1
View File
@@ -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
+7 -2
View File
@@ -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())),
}
}