When using the starting points in the structure, Rust does not allow to get the default value.
eg:
#[derive(Default)] struct Foo { bar: *mut Foo, baz: usize, }
Reports
error[E0277]: the trait bound `*mut Foo: std::default::Default` is not satisfied
I tried this, but it does not work:
impl Default for *mut Foo { fn default() -> *mut Foo { ptr::null_mut() } }
This gives an error:
impl doesn't use types inside crate
Is there a way to declare Default for a raw pointer?
Otherwise, I will have to write explicit Default functions for any struct that contains a raw pointer, in this example OK, but for large structures this can be tedious, so I would like to be able to avoid this in some cases.
source share