Closed j1elo closed 4 years ago
DeserializeOwned
comes from the from_captures()
function, which has this prototype:
pub fn from_captures<D>(
re: &Regex,
input: &str,
) -> Result<D, Error>
where
D: DeserializeOwned,
{
[...]
}
Hi, serialization/deserialization is an optional feature in euclid. You can enable it in your cargo.toml by replacing euclid = "0.20.6"
(or whatever version you depend on) with euclid = { version = "0.20.6", features = ["serde"] }
Hi, serialization/deserialization is an optional feature in euclid. You can enable it in your cargo.toml by replacing
euclid = "0.20.6"
(or whatever version you depend on) witheuclid = { version = "0.20.6", features = ["serde"] }
Thanks a lot! It solved the compilation issue. For the next time that something similar happens, how should I have been able to discover that serde
is an optional feature of euclid that has to be enabled?
(also the problem now changed to a runtime error because the sample code shown fails with this error: invalid type: map, expected a tuple of size 3
; this is me not knowing how to use the lib and not really a bug (so far), so it should be talked about in a user forum, is there a specific one for euclid?)
For the next time that something similar happens, how should I have been able to discover that serde is an optional feature of euclid that has to be enabled?
Good question. I don't have good answer for it. Ideally the crate's documentation would explain what the optional feature flags are and how they affect the API, but euclid does a poor job of it. Once you get into reading the code, when you see #[cfg(feature="foo")]
it means that the following item is only compiled if the feature "foo" is enabled.
also the problem now changed to a runtime error
I don't know anything about recap, but from this error it seems that the format you are providing in your example doesn't match the form it expects for deserialization. You could try to serialize something with the serializer used in recap and compare what the result looks like with the format you are using in your example.
I saw some #[cfg(feature="foo")]
but didn't know those meant features to be enabled in Cargo.toml. So, nice! thanks for the tips.
This is not a bug in euclid so I'm closing this issue.
I'm trying to deserialize a Point3D using the recap crate, like this:
Cargo.toml
main.rs
However I get this error in
from_captures
:I've been reading the code trying to understand what is going on, as it seems that Serde has a default implementation of
DeserializeOwned
for all types that implementDeserialize<'de>
:(from serde)
and I can see that euclid seems to implement
Deserialize<'de>
, in point.rs:However I'm a total beginner learning Rust, and I'm just learning to interpret trait implementations and lifetimes, so I'm not able to work out by myself what is wrong and what should be done to fix it, in case it's not an actual bug in euclid (is it?)