-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Diff Visitor for BlueprintZoneConfigs (#7336)
This visitor walks a diffus generated diff and provides callbacks for users to hook into the parts of the diff that they care about. To keep things minimal, we don't provide callback trait methods for copies (when nothing changes), and we don't provide methods for most diffus_derive generated types (the ones that start with `Edited`). We anticipate composing these visitors to build up a full diff of a Blueprint. They can also be used individually as demonstrated with the included tests.
- Loading branch information
1 parent
1c92838
commit c03eb51
Showing
9 changed files
with
583 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! An API for visiting diffs between blueprints generated via [diffus](https://github.com/oxidecomputer/diffus) | ||
//! | ||
//! Modelled after [`syn::visit`](https://docs.rs/syn/1/syn/visit). | ||
pub mod visit_blueprint_zones_config; | ||
|
||
use diffus::edit::enm; | ||
use omicron_uuid_kinds::{OmicronZoneUuid, SledUuid}; | ||
|
||
use super::{ | ||
BlueprintZoneConfig, BlueprintZoneDisposition, BlueprintZoneType, | ||
BlueprintZonesConfig, EditedBlueprintZoneConfig, | ||
}; | ||
|
||
/// A context for blueprint related visitors | ||
#[derive(Debug, Clone, Default)] | ||
pub struct BpVisitorContext { | ||
pub sled_id: Option<SledUuid>, | ||
pub zone_id: Option<OmicronZoneUuid>, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct Change<'e, T> { | ||
pub before: &'e T, | ||
pub after: &'e T, | ||
} | ||
|
||
impl<'e, T> Change<'e, T> { | ||
pub fn new(before: &'e T, after: &'e T) -> Change<'e, T> { | ||
Change { before, after } | ||
} | ||
} | ||
|
||
impl<'e, T> From<(&'e T, &'e T)> for Change<'e, T> { | ||
fn from(value: (&'e T, &'e T)) -> Self { | ||
Change::new(value.0, value.1) | ||
} | ||
} | ||
|
||
impl<'e, T, Diff> From<&enm::Edit<'e, T, Diff>> for Change<'e, T> { | ||
fn from(value: &enm::Edit<'e, T, Diff>) -> Self { | ||
match value { | ||
enm::Edit::VariantChanged(before, after) => { | ||
Change::new(before, after) | ||
} | ||
enm::Edit::AssociatedChanged { before, after, .. } => { | ||
Change::new(before, after) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.