Skip to content

Commit 7abef23

Browse files
authored
Merge branch 'main' into chore/kube-2.0.0
2 parents fb343c8 + f93c552 commit 7abef23

File tree

8 files changed

+374
-98
lines changed

8 files changed

+374
-98
lines changed

crates/stackable-versioned-macros/src/attrs/item/field.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use darling::{Error, FromField, Result, util::Flag};
1+
use darling::{Error, FromField, FromMeta, Result, util::Flag};
22
use syn::{Attribute, Ident};
33

44
use crate::{
@@ -44,6 +44,10 @@ pub struct FieldAttributes {
4444
/// is needed to let the macro know to generate conversion code with support
4545
/// for tracking across struct boundaries.
4646
pub nested: Flag,
47+
48+
/// Provide a hint if a field is wrapped in either `Option` or `Vec` to
49+
/// generate correct code in the `From` impl blocks.
50+
pub hint: Option<Hint>,
4751
}
4852

4953
impl FieldAttributes {
@@ -81,3 +85,10 @@ impl FieldAttributes {
8185
Ok(())
8286
}
8387
}
88+
89+
/// Supported field hints.
90+
#[derive(Debug, FromMeta)]
91+
pub enum Hint {
92+
Option,
93+
Vec,
94+
}

crates/stackable-versioned-macros/src/codegen/item/field.rs

Lines changed: 153 additions & 97 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use stackable_versioned::versioned;
2+
// ---
3+
#[versioned(version(name = "v1alpha1"), version(name = "v1alpha2"))]
4+
// ---
5+
mod versioned {
6+
struct Foo {
7+
#[versioned(hint(option))]
8+
bar: Option<String>,
9+
10+
#[versioned(hint(vec))]
11+
baz: Vec<usize>,
12+
13+
quux: bool,
14+
}
15+
}
16+
// ---
17+
fn main() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use stackable_versioned::versioned;
2+
// ---
3+
#[versioned(
4+
version(name = "v1alpha1"),
5+
version(name = "v1alpha2"),
6+
options(k8s(experimental_conversion_tracking))
7+
)]
8+
// ---
9+
mod versioned {
10+
struct Foo {
11+
#[versioned(nested, hint(option))]
12+
bar: Option<Bar>,
13+
14+
#[versioned(hint(vec))]
15+
baz: Vec<usize>,
16+
17+
quux: bool,
18+
}
19+
20+
struct Bar {
21+
bar_bar: String,
22+
23+
#[versioned(added(since = "v1alpha2"))]
24+
baz_baz: u8,
25+
}
26+
}
27+
// ---
28+
fn main() {}

crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@conversion_hints.rs.snap

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@conversion_tracking_hints.rs.snap

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-versioned-macros/tests/trybuild.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod inputs {
1919
mod pass {
2020
// mod added;
2121
// mod basic;
22+
// mod conversion_hints;
23+
// mod conversion_tracking_hints;
2224
// mod conversion_tracking;
2325
// mod crate_overrides;
2426
// mod docs;

crates/stackable-versioned/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add new `#[versioned(hint)]` argument to provide type hints for struct fields ([#1089]).
10+
- `#[versioned(hint(option))]` for fields wrapped in an `Option`. Generates `.map(Into::into)`.
11+
- `#[versioned(hint(vec))]` for fields wrapped in an `Vec`. Generates `.into_iter().map(Into::into).collect()`.
12+
713
### Fixed
814

915
- Correctly emit enum variant fields in `From` impl blocks ([#1086]).
1016

1117
[#1086]: https://github.com/stackabletech/operator-rs/pull/1086
18+
[#1089]: https://github.com/stackabletech/operator-rs/pull/1089
1219

1320
## [0.8.1] - 2025-08-21
1421

0 commit comments

Comments
 (0)