I have a library that I'm writing that's entirely based around ownership. Mostly as an academic exercise, I'm looking at migrating it to use lifetimes. Given something like this,
#[derive(Default)]
struct Foo { test: i32 }
#[derive(Default)]
struct Bar { foo: Foo }
Now I can easily modify bar to use lifetimes,
#[derive(Default)]
struct Foo { test: i32 }
struct Bar<'a> { foo: &'a Foo }
But that'll trigger an error,
error[E0277]: the trait bound `&Foo: Default` is not satisfied
--> src/main.rs:6:18
|
5 | #[derive(Default)]
| ------- in this derive macro expansion
6 | struct Bar<'a> { foo: &'a Foo }
| ^^^^^^^^^^^^ the trait `Default` is not implemented for `&Foo`
|
= help: the trait `Default` is implemented for `Foo`
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
How can I get around this?