error: lifetime may not live long enough
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
| |
| lifetime `'de` defined here
| associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'de`
5 | struct A<'a> {
| -- lifetime `'a` defined here
|
= help: consider adding the following bound: `'de: 'a`
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
Isn't it more reasonable to handle Cow in a way similar to serde so that deserializing Cow does not borrow?
I wrote crate CowBytes to solve this problem: https://github.com/seekstar/CowBytes. It seems that it works fine. I would like to submit a PR if the maintainer of serde_bytes consents.
Cow
is handled in this way inserde
. Butserde-bytes
deserializesCow
by borrowing. As a result, this compiles:But this does not compile:
The error message generated by compiler:
Isn't it more reasonable to handle
Cow
in a way similar toserde
so that deserializingCow
does not borrow?