Add an attribute to the field: #[serde(borrow)]
. That will indicate to serde that it should be borrowing the value. You must provide this attribute for every borrow except for &str
and &[u8]
.
Source: https://serde.rs/lifetimes.html#borrowing-data-in-a-derived-impl
More Related Contents:
- Why is a trait not implemented for a type that clearly has it implemented?
- How to transform fields during deserialization using Serde?
- Lifetime error when creating a function that returns a value implementing serde::Deserialize
- How to transform fields during serialization using Serde?
- How can I distinguish between a deserialized field that is missing and one that is null?
- How to implement `serde::Serialize` for a boxed trait object?
- How to fix lifetime error when function returns a serde Deserialize type?
- How can I include a module from another file from the same project?
- What does “Sized is not implemented” mean?
- How do I implement a trait I don’t own for a type I don’t own?
- What makes something a “trait object”?
- Cannot borrow as immutable because it is also borrowed as mutable in function arguments
- What is the relation between auto-dereferencing and deref coercion?
- What is the return type of the indexing operation?
- How to do a binary search on a Vec of floats?
- Change enum variant while moving the field to the new variant
- I implemented a trait for another trait but cannot call methods from both traits
- When is it useful to define multiple lifetimes in a struct?
- What is the difference between Copy and Clone?
- Is it possible to have stack allocated arrays with the size determined at runtime in Rust?
- Temporary value is freed at the end of this statement [duplicate]
- What is the right way to allocate data to pass to an FFI call?
- Sharing a struct with trait objects as properties across threads
- Read large files line by line in Rust [duplicate]
- How do I print an integer in binary with leading zeros?
- What does Rust’s unary || (parallel pipe) mean?
- How does Rust’s type inference work across multiple statements?
- Why does Valgrind not detect a memory leak in a Rust program using nightly 1.29.0?
- What is the null pointer optimization in Rust?
- How to pass rustc flags to cargo?