Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
11 changes: 9 additions & 2 deletions Cargo.lock

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

21 changes: 21 additions & 0 deletions crates/stackable-versioned-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "stackable-versioned-macros"
version = "0.1.0"
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true

[lib]
proc-macro = true

[dependencies]
k8s-version = { path = "../k8s-version", features = ["darling"] }

darling.workspace = true
proc-macro2.workspace = true
syn.workspace = true
quote.workspace = true

[dev-dependencies]
rstest.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ impl ContainerAttributes {
///
/// - `name` of the version, like `v1alpha1`.
/// - `deprecated` flag to mark that version as deprecated.
/// - `skip` option to skip generating various pieces of code.
#[derive(Clone, Debug, FromMeta)]
pub(crate) struct VersionAttributes {
pub(crate) deprecated: Flag,
pub(crate) name: Version,
pub(crate) skip: Option<SkipOptions>,
}

/// This struct contains supported container options.
Expand All @@ -95,7 +97,19 @@ pub(crate) struct VersionAttributes {
///
/// - `allow_unsorted`, which allows declaring versions in unsorted order,
/// instead of enforcing ascending order.
/// - `skip` option to skip generating various pieces of code.
#[derive(Clone, Debug, Default, FromMeta)]
pub(crate) struct ContainerOptions {
pub(crate) allow_unsorted: Flag,
pub(crate) skip: Option<SkipOptions>,
}

/// This struct contains supported skip options.
///
/// Supported options are:
///
/// - `from` flag, which skips generating [`From`] implementations when provided.
#[derive(Clone, Debug, Default, FromMeta)]
pub(crate) struct SkipOptions {
pub(crate) from: Flag,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use darling::{util::SpannedValue, Error, FromField, FromMeta};
use k8s_version::Version;
use syn::{Field, Ident};
use proc_macro2::Span;
use syn::{Field, Ident, Path};

use crate::{attrs::container::ContainerAttributes, consts::DEPRECATED_PREFIX};

Expand Down Expand Up @@ -40,6 +41,16 @@ pub(crate) struct FieldAttributes {
#[derive(Clone, Debug, FromMeta)]
pub(crate) struct AddedAttributes {
pub(crate) since: SpannedValue<Version>,

#[darling(rename = "default", default = "default_default_fn")]
pub(crate) default_fn: SpannedValue<Path>,
}

fn default_default_fn() -> SpannedValue<Path> {
SpannedValue::new(
syn::parse_str("std::default::Default::default").unwrap(),
Span::call_site(),
)
}

#[derive(Clone, Debug, FromMeta)]
Expand Down
Loading