Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Struct {
{
fn tracking_from(#from_struct_ident: #from_module_ident::#struct_ident #type_generics, status: &mut __SvStatus, parent: &str) -> Self {
// TODO (@Techassi): Only emit this if any of the fields below need it
use #versioned_path::TrackingInto as _;
use #versioned_path::{ExtractIfExt as _, TrackingInto as _};

#json_paths
// Depending on the direction, we need to either insert changed values into
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Struct {
return None;
}

let match_arms: TokenStream = self
let removals: TokenStream = self
.fields
.iter()
.filter_map(|f| f.generate_for_status_removal(direction, next_version, mod_gen_ctx))
Expand All @@ -273,16 +273,13 @@ impl Struct {
match direction {
Direction::Upgrade => {
let next_version_string = next_version.inner.to_string();
let versioned_path = &*mod_gen_ctx.crates.versioned;

Some(quote! {
// NOTE (@Techassi): This is an awkward thing to do. Can we possibly use &str for the keys here?
if let Some(upgrades) = status.changes().upgrades.remove(&#next_version_string.to_owned()) {
for #versioned_path::ChangedValue { json_path, value } in upgrades {
match json_path {
#match_arms
_ => unreachable!(),
}
if let Some(upgrades) = status.changes().upgrades.get_mut(#next_version_string) {
#removals

if upgrades.is_empty() {
status.changes().upgrades.remove(#next_version_string);
}
}
})
Expand Down
11 changes: 8 additions & 3 deletions crates/stackable-versioned-macros/src/codegen/item/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl VersionedField {
let changes = self.changes.as_ref()?;

let yaml_serde_path = &*mod_gen_ctx.crates.yaml_serde;
let versioned_path = &*mod_gen_ctx.crates.versioned;

match direction {
Direction::Upgrade => {
Expand All @@ -360,11 +361,15 @@ impl VersionedField {
// we only need to generate code if the next change is "Addition".
ItemStatus::Addition { ident, .. } => {
let json_path_ident = ident.json_path_ident();
let expect_message = format!(
"internal error: {{{json_path_ident}}} must be serializable for spec.{ident}"
);

Some(quote! {
json_path if json_path == #json_path_ident => {
spec.#ident = #yaml_serde_path::from_value(value).unwrap();
},
if let Some(#versioned_path::ChangedValue { value, .. }) = upgrades.extract_first_if(|u| u.json_path == #json_path_ident) {
// TODO (@Techassi): Switch to serde_json
spec.#ident = #yaml_serde_path::from_value(value).expect(#expect_message);
}
})
}
_ => None,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading