Skip to content

Commit

Permalink
Merge pull request #242 from ctron/feature/partial_eq_1
Browse files Browse the repository at this point in the history
Allow CRD to implement PartialEq trait
  • Loading branch information
clux authored May 21, 2020
2 parents 21b01d3 + 7b7fd48 commit 24c929a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct CustomResource {
group: String,
version: String,
namespaced: bool,
partial_eq: bool,
status: Option<String>,
shortnames: Vec<String>,
apiextensions: String,
Expand All @@ -34,6 +35,7 @@ impl CustomDerive for CustomResource {
let mut group = None;
let mut version = None;
let mut namespaced = false;
let mut partial_eq = false;
let mut status = None;
let mut apiextensions = "v1".to_string();
let mut scale = None;
Expand Down Expand Up @@ -134,6 +136,9 @@ impl CustomDerive for CustomResource {
if path.is_ident("namespaced") {
namespaced = true;
continue;
} else if path.is_ident("partial_eq") {
partial_eq = true;
continue;
} else {
&meta
}
Expand Down Expand Up @@ -188,6 +193,7 @@ impl CustomDerive for CustomResource {
group,
version,
namespaced,
partial_eq,
printcolums,
status,
shortnames,
Expand All @@ -206,6 +212,7 @@ impl CustomDerive for CustomResource {
kind,
version,
namespaced,
partial_eq,
status,
shortnames,
printcolums,
Expand Down Expand Up @@ -237,8 +244,14 @@ impl CustomDerive for CustomResource {
};
let has_status = status.is_some();

let mut derives = vec!["Serialize", "Deserialize", "Clone", "Debug"];
if partial_eq {
derives.push("PartialEq");
}
let derives :Vec<Ident>= derives.iter().map(|s|format_ident!("{}", s)).collect();

let root_obj = quote! {
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(#(#derives),*)]
#[serde(rename_all = "camelCase")]
#visibility struct #rootident {
#visibility api_version: String,
Expand Down

0 comments on commit 24c929a

Please sign in to comment.