-
Notifications
You must be signed in to change notification settings - Fork 4
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
BREAKING CHANGE: add non-geospatial option #2
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -61,6 +61,9 @@ pub struct Supercluster { | |||
|
|||
/// Clusters metadata. | |||
cluster_props: Vec<JsonObject>, | |||
|
|||
/// Use non-geospatial coordinates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use .
in the end instead of ?
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and maybe describe what it means so it is easier for everyone to understand.
/// # Returns | ||
/// | ||
/// A new `Supercluster` instance with the given configuration. | ||
pub fn new_non_geospatial(options: Options) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a new method that is exactly the same except for the use_non_geospatial_coords
property value. We can reuse the existing new
by setting the cluster_type
enum property from the options
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you advise how to do this? I am fairly new to Rust, and I cannot think of a way to add a property to Options
without breaking backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure,
- add a new boolean flag here to be able to manage it when setting a new cluster: https://github.com/chargetrip/supercluster-rs/blob/main/src/lib.rs#L27.
- add a boolean flag here, to be able to access it through the cluster itself: https://github.com/chargetrip/supercluster-rs/blob/main/src/lib.rs#L49.
- after that, you will have a property value to set here during the initialisation process: https://github.com/chargetrip/supercluster-rs/blob/main/src/lib.rs#L87.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does not sound right. If let's say I add a new parameter Options
is_non_geospatial: bool
, then any place that I set the Options
that are passed to Supercluster
will need to include is_non_geospatial
in those options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using an enum instead of a boolean flag? This way it is clearer which cluster type we want to use. Check the comments above about this suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, we can use an enum type to control it instead of a boolean flag.
The only place we need options is when we initialise Supercluster
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. So, I add:
cluster_type: ClusterType
to Options
.
Now any previous code that instantiates a new Supercluster
that wants to use the default geo-spatial use-case will break because cluster_type
is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, we introduce a breaking change but I will mention it in the upcoming Changelog.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, as long as you are cool with it, I like this a lot more.
I was mostly trying to protect against a breaking change.
In other languages (i.e. Python), I would just introduce the new option with a default value. I wish there was some way to do something similar in Rust. Alas, Rust demands being explicit. Not a bad thing, but just different.
Ok, I will introduce the breaking change as suggested!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
I will update CI to generate release notes and it will be visible that we generated a breaking change.
data: &[f64], | ||
i: usize, | ||
cluster_props: &[JsonObject], | ||
use_non_geospatial_coords: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the description of the get_cluster_json
for this property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be an enum value from cluster_type
instead of a boolean flag.
@@ -61,6 +61,9 @@ pub struct Supercluster { | |||
|
|||
/// Clusters metadata. | |||
cluster_props: Vec<JsonObject>, | |||
|
|||
/// Use non-geospatial coordinates? | |||
use_non_geospatial_coords: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about replacing it with an enum:
pub enum ClusterType {
GeoSpatial,
NonGeoSpatial,
}
and use it instead of a boolean flag. This way it will be easier to understand and maintain.
📇 Description
This adds a new non-geospatial option.
I still have yet to update the comments and document and add more test cases. I can add those things if there is any interest in this PR.
For now, I mostly wanted to confirm that it can be done.
🚨 Checklist
🧪 Tests