Skip to content

Commit

Permalink
Clippy nightly fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Dec 21, 2024
1 parent 1b0ad5e commit 060ad64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions kube-core/src/cel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl FromStr for Reason {
/// use kube::core::{Rule, Reason, Message, validate};
///
/// let mut schema = Schema::Object(Default::default());
/// let rules = vec![Rule{
/// let rules = &[Rule{
/// rule: "self.spec.host == self.url.host".into(),
/// message: Some("must be a URL with the host matching spec.host".into()),
/// field_path: Some("spec.host".into()),
Expand All @@ -185,7 +185,7 @@ impl FromStr for Reason {
///```
#[cfg(feature = "schema")]
#[cfg_attr(docsrs, doc(cfg(feature = "schema")))]
pub fn validate(s: &mut Schema, rules: Vec<Rule>) -> Result<(), serde_json::Error> {
pub fn validate(s: &mut Schema, rules: &[Rule]) -> Result<(), serde_json::Error> {
match s {
Schema::Bool(_) => (),
Schema::Object(schema_object) => {
Expand All @@ -211,7 +211,7 @@ pub fn validate(s: &mut Schema, rules: Vec<Rule>) -> Result<(), serde_json::Erro
///
/// let gen = &mut schemars::gen::SchemaSettings::openapi3().into_generator();
/// let mut schema = MyStruct::json_schema(gen);
/// let rules = vec![Rule::new("self != oldSelf")];
/// let rules = &[Rule::new("self != oldSelf")];
/// validate_property(&mut schema, 0, rules)?;
/// assert_eq!(
/// serde_json::to_string(&schema).unwrap(),
Expand All @@ -224,7 +224,7 @@ pub fn validate(s: &mut Schema, rules: Vec<Rule>) -> Result<(), serde_json::Erro
pub fn validate_property(
s: &mut Schema,
property_index: usize,
rules: Vec<Rule>,
rules: &[Rule],
) -> Result<(), serde_json::Error> {
match s {
Schema::Bool(_) => (),
Expand Down
16 changes: 7 additions & 9 deletions kube-derive/src/cel_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn derive_validated_schema(input: TokenStream) -> TokenStream {
// Remove all unknown attributes from the original structure copy
// Has to happen on the original definition at all times, as we don't have #[derive] stanzes.
let attribute_whitelist = ["serde", "schemars", "doc"];
ast.attrs = remove_attributes(&ast.attrs, attribute_whitelist.to_vec());
ast.attrs = remove_attributes(&ast.attrs, &attribute_whitelist);

let struct_data = match ast.data {
syn::Data::Struct(ref mut struct_data) => struct_data,
Expand All @@ -96,7 +96,7 @@ pub(crate) fn derive_validated_schema(input: TokenStream) -> TokenStream {

// Remove all unknown attributes from each field
// Has to happen on the original definition at all times, as we don't have #[derive] stanzes.
field.attrs = remove_attributes(&field.attrs, attribute_whitelist.to_vec());
field.attrs = remove_attributes(&field.attrs, &attribute_whitelist);

if rules.is_empty() {
continue;
Expand All @@ -116,7 +116,7 @@ pub(crate) fn derive_validated_schema(input: TokenStream) -> TokenStream {
}

let merge = &mut Validated::json_schema(gen);
#kube_core::validate_property(merge, 0, [#(#rules)*].to_vec()).unwrap();
#kube_core::validate_property(merge, 0, &[#(#rules)*]).unwrap();
#kube_core::merge_properties(s, merge);
}
});
Expand All @@ -141,7 +141,7 @@ pub(crate) fn derive_validated_schema(input: TokenStream) -> TokenStream {

use #kube_core::{Rule, Message, Reason};
let s = &mut #ident::json_schema(gen);
#kube_core::validate(s, [#(#struct_rules)*].to_vec()).unwrap();
#kube_core::validate(s, &[#(#struct_rules)*]).unwrap();
#(#property_modifications)*
s.clone()
}
Expand All @@ -150,7 +150,7 @@ pub(crate) fn derive_validated_schema(input: TokenStream) -> TokenStream {
}

// Remove all unknown attributes from the list
fn remove_attributes(attrs: &Vec<Attribute>, witelist: Vec<&str>) -> Vec<Attribute> {
fn remove_attributes(attrs: &[Attribute], witelist: &[&str]) -> Vec<Attribute> {
attrs
.iter()
.filter(|attr| witelist.iter().any(|i| attr.path().is_ident(i)))
Expand All @@ -176,8 +176,6 @@ fn test_derive_validated() {

#[cfg(test)]
mod tests {
use std::{env, fs};

use prettyplease::unparse;
use syn::parse::{Parse as _, Parser as _};

Expand Down Expand Up @@ -212,7 +210,7 @@ mod tests {
}
use ::kube::core::{Rule, Message, Reason};
let s = &mut FooSpec::json_schema(gen);
::kube::core::validate(s, ["true".into()].to_vec()).unwrap();
::kube::core::validate(s, &["true".into()]).unwrap();
{
#[derive(::serde::Serialize, ::schemars::JsonSchema)]
#[automatically_derived]
Expand All @@ -221,7 +219,7 @@ mod tests {
foo: String,
}
let merge = &mut Validated::json_schema(gen);
::kube::core::validate_property(merge, 0, ["true".into()].to_vec()).unwrap();
::kube::core::validate_property(merge, 0, &["true".into()]).unwrap();
::kube::core::merge_properties(s, merge);
}
s.clone()
Expand Down

0 comments on commit 060ad64

Please sign in to comment.