I'm trying to create a global instance that I can borrow a reference too,
const GLOBAL_FOO: &Foo = &Foo::default();
impl<'a> Default for Bar<'a> {
fn default() -> Self {
Self { foo: GLOBAL_FOO }
}
}
But when I do this, I get an error,
error[E0015]: cannot call non-const fn `<Foo as Default>::default` in constants
--> src/main.rs:8:27
|
8 | const GLOBAL_FOO: &Foo = &Foo::default();
| ^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
For more information about this error, try `rustc --explain E0015`.
How can I work around calling default in a const to accomplish this?