-
Notifications
You must be signed in to change notification settings - Fork 40
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
[reconfigurator] Introduce IdMap
and use it in BlueprintZonesConfig
#7327
base: main
Are you sure you want to change the base?
Conversation
{ | ||
"$ref": "#/components/schemas/IdMapBlueprintZoneConfig" | ||
} | ||
] |
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'm not sure why this changed, exactly. Does JsonSchema
do something special for BTreeMap
that it doesn't know how to do for IdMap
?
I think this is semantically equivalent, though; allOf
says to apply all of the inner subschemas, and since this subschema is the same as what the prior schema was, this is basically undoing an inlining?
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.
Looks great. Thanks for all the work here @jgallagher.
I have no idea about the JsonSchema question. Maybe @ahl does.
@@ -794,7 +795,7 @@ impl DataStore { | |||
e.to_string() | |||
)) | |||
})?; | |||
sled_zones.zones.insert(zone.id, zone); | |||
sled_zones.zones.insert(zone); |
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.
Nice!
Self { original_id: borrowed.id(), borrowed: Some(borrowed) } | ||
} | ||
|
||
pub fn into_ref(mut self) -> &'a T { |
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.
Nice closing of this loophole too!
@andrewjstone mentioned being bothered by our
BTreeMap<Id, ValueWithAnId>
maps on #7315:This has bugged me too, and adding a blippy check crossed my mind. But I think it would be better to make this just not possible, so this PR introduces a newtype wrapper around
BTreeMap<T::Id, T>
that enforces "key must be value's ID" via a mix of compile time API constraints (e.g.,insert
only takes the value and generates the key on its own) and runtime checks (e.g., when mutating a value stored in the map, it will panic if that mutation changes the ID of the value).The new code is all in
id_map.rs
, and the rest of the changes are replacing theBlueprintZonesConfig
map with it. If this looks reasonable to folks, followup PRs to change the other similarBTreeMap
s to useIdMap
should be straightforward.