-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impl Default for Coordinates #612
Comments
It is possible to add this implementation. @sbland Would you mind sharing your use case for this? |
@frewsxcv I have many structs that use the Point struct and can otherwise implement default with // #[derive(Default)
pub struct CellState {
pub id: u32,
pub position: Point<f64>,
pub population: u32,
}
// All this could be removed if Point had a default implementation
impl Default for CellState {
fn default() -> CellState {
CellState {
id: 0,
position: point!(x:0.0, y:0.0),
population: 0,
}
}
} I can submit a quick PR if there are no potential issues to this. |
You probably already know, but just in case, to get defaults for the other fields you can write:
There is always potential for issues 😉, but I think relying on T::Default seems pretty reasonable - for 99.9% of people, that means they'll get a point at (0,0). |
Thanks @michaelkirk I use this for instantiating later but still need to put in |
616: Implement Default for Coordinate and Point r=frewsxcv a=sbland - [/ ] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md). - [/ ] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users. --- PR for issue #612 Co-authored-by: Sam Bland <sbland.co.uk@gmail.com> Co-authored-by: Corey Farwell <coreyf@rwell.org>
Done in #616 |
Can we safely implement default for the Coordinate struct as below:
The text was updated successfully, but these errors were encountered: