#[derive(Default,Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
// both of these lines work
let p: Point = Default::default();
let p = <Point as Default>::default();
println!("{:?}", p);
}
Exactly, code doesn't compile because of "changes" field in trait. I want "changes" field to be accessible for structs implementing Aggregate trait. Sorry, but I don't get how #[derive(Default)] could achieve that.
The traits cannot carry data, they're really just behavioral. A common solution to your example would be to have the Aggregate trait expect the type to define a fn changes(&mut self) -> &mut Vec<Event>;, or fn add_change(&mut self, e: Event); if you want to be storage-agnostic.
There is an RFC that would allow this, but for now you will need to include a changes field in the struct and add a .changes() method to the trait to access it.
In the end I've settled with macro implemented for default "changes" field. Playground code snippet - Rust Playground for anyone interested or willing to comment on implementation.