Skip to content

Commit

Permalink
Pass cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Sep 24, 2023
1 parent afb00be commit ef962c9
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 52 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ num-traits = { version = "=0.2" }
octocrab = { git = "https://github.com/ulagbulag/octocrab.git", default-features = false, features = [
"rustls-tls",
] }
ordered-float = { version = "4.0", default-features = false, features = [
"bytemuck",
"schemars",
"serde",
"std",
] }
ort = { version = "=1.14.8", default-features = false, features = [
# Common
"copy-dylibs",
Expand Down
1 change: 1 addition & 0 deletions dash/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ anyhow = { workspace = true }
chrono = { workspace = true }
k8s-openapi = { workspace = true }
kube = { workspace = true, features = ["derive"] }
ordered-float = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
103 changes: 77 additions & 26 deletions dash/api/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl ModelCrd {
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct ModelStatus {
#[serde(default)]
Expand All @@ -82,7 +84,9 @@ pub type ModelFieldsNativeSpec = ModelFieldsSpec<ModelFieldKindNativeSpec>;
pub type ModelFieldNativeSpec = ModelFieldSpec<ModelFieldKindNativeSpec>;
pub type ModelFieldExtendedSpec = ModelFieldSpec<ModelFieldKindExtendedSpec>;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct ModelFieldSpec<Kind = ModelFieldKindSpec> {
pub name: String,
Expand Down Expand Up @@ -128,14 +132,27 @@ impl ModelFieldSpec {
}
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[derive(
Copy,
Clone,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct ModelFieldAttributeSpec {
#[serde(default)]
pub optional: bool,
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ModelFieldKindSpec {
Native(ModelFieldKindNativeSpec),
Extended(ModelFieldKindExtendedSpec),
Expand Down Expand Up @@ -164,19 +181,19 @@ mod _impl_jsonschema_for_model_field_kind_spec {
},
Integer {
#[serde(default)]
default: &'a Option<i64>,
default: &'a Option<super::Integer>,
#[serde(default)]
minimum: &'a Option<i64>,
minimum: &'a Option<super::Integer>,
#[serde(default)]
maximum: &'a Option<i64>,
maximum: &'a Option<super::Integer>,
},
Number {
#[serde(default)]
default: &'a Option<f64>,
default: &'a Option<super::Number>,
#[serde(default)]
minimum: &'a Option<f64>,
minimum: &'a Option<super::Number>,
#[serde(default)]
maximum: &'a Option<f64>,
maximum: &'a Option<super::Number>,
},
String {
#[serde(default)]
Expand Down Expand Up @@ -293,19 +310,19 @@ mod _impl_jsonschema_for_model_field_kind_spec {
},
Integer {
#[serde(default)]
default: Option<i64>,
default: Option<super::Integer>,
#[serde(default)]
minimum: Option<i64>,
minimum: Option<super::Integer>,
#[serde(default)]
maximum: Option<i64>,
maximum: Option<super::Integer>,
},
Number {
#[serde(default)]
default: Option<f64>,
default: Option<super::Number>,
#[serde(default)]
minimum: Option<f64>,
minimum: Option<super::Number>,
#[serde(default)]
maximum: Option<f64>,
maximum: Option<super::Number>,
},
String {
#[serde(default)]
Expand Down Expand Up @@ -448,6 +465,20 @@ mod _impl_jsonschema_for_model_field_kind_spec {
}

impl ModelFieldKindSpec {
pub fn get_children(&self) -> Option<&Vec<String>> {
match self {
Self::Native(spec) => spec.get_children(),
Self::Extended(spec) => spec.get_children(),
}
}

pub fn get_children_mut(&mut self) -> Option<&mut Vec<String>> {
match self {
Self::Native(spec) => spec.get_children_mut(),
Self::Extended(spec) => spec.get_children_mut(),
}
}

pub const fn to_type(&self) -> ModelFieldKindType {
match self {
Self::Native(spec) => ModelFieldKindType::Native(spec.to_type()),
Expand All @@ -456,7 +487,9 @@ impl ModelFieldKindSpec {
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub enum ModelFieldKindNativeSpec {
// BEGIN primitive types
Expand All @@ -467,19 +500,19 @@ pub enum ModelFieldKindNativeSpec {
},
Integer {
#[serde(default)]
default: Option<i64>,
default: Option<Integer>,
#[serde(default)]
minimum: Option<i64>,
minimum: Option<Integer>,
#[serde(default)]
maximum: Option<i64>,
maximum: Option<Integer>,
},
Number {
#[serde(default)]
default: Option<f64>,
default: Option<Number>,
#[serde(default)]
minimum: Option<f64>,
minimum: Option<Number>,
#[serde(default)]
maximum: Option<f64>,
maximum: Option<Number>,
},
String {
#[serde(default)]
Expand Down Expand Up @@ -583,7 +616,9 @@ impl ModelFieldKindNativeSpec {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub enum ModelFieldKindStringSpec {
Dynamic {},
Expand All @@ -603,14 +638,24 @@ impl Default for ModelFieldKindStringSpec {
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub enum ModelFieldKindExtendedSpec {
// BEGIN reference types
Model { name: String },
}

impl ModelFieldKindExtendedSpec {
pub fn get_children(&self) -> Option<&Vec<String>> {
None
}

pub fn get_children_mut(&mut self) -> Option<&mut Vec<String>> {
None
}

pub const fn to_type(&self) -> ModelFieldKindExtendedType {
match self {
// BEGIN reference types
Expand Down Expand Up @@ -737,7 +782,9 @@ pub enum ModelFieldDateTimeDefaultType {
Now,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct ModelCustomResourceDefinitionRefSpec {
pub name: String,
Expand Down Expand Up @@ -774,3 +821,7 @@ impl Default for ModelState {
Self::Pending
}
}

pub type Integer = i64;

pub type Number = ::ordered_float::OrderedFloat<f64>;
10 changes: 7 additions & 3 deletions dash/controller/src/validator/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ impl ModelFieldsParser {
})
}
Some("number") => {
let default = prop.default.as_ref().and_then(|e| e.0.as_f64());
let minimum = prop.minimum;
let maximum = prop.maximum;
let default = prop
.default
.as_ref()
.and_then(|e| e.0.as_f64())
.map(Into::into);
let minimum = prop.minimum.map(Into::into);
let maximum = prop.maximum.map(Into::into);

Some(ModelFieldKindNativeSpec::Number {
default,
Expand Down
12 changes: 6 additions & 6 deletions dash/provider/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use anyhow::{anyhow, bail, Error, Result};
use async_recursion::async_recursion;
use chrono::{DateTime, Utc};
use dash_api::model::{
ModelFieldDateTimeDefaultType, ModelFieldKindNativeSpec, ModelFieldNativeSpec, ModelFieldSpec,
ModelFieldsNativeSpec, ModelFieldsSpec,
Integer, ModelFieldDateTimeDefaultType, ModelFieldKindNativeSpec, ModelFieldNativeSpec,
ModelFieldSpec, ModelFieldsNativeSpec, ModelFieldsSpec, Number,
};
use inflector::Inflector;
use regex::Regex;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl InputTemplate {
minimum,
maximum,
} => {
let value_i64: i64 = value.parse()?;
let value_i64: Integer = value.parse()?;
assert_cmp(
&name,
&value_i64,
Expand All @@ -111,7 +111,7 @@ impl InputTemplate {
minimum,
maximum,
} => {
let value_f64: f64 = value.parse()?;
let value_f64: Number = value.parse()?;
assert_cmp(
&name,
&value_f64,
Expand Down Expand Up @@ -250,7 +250,7 @@ impl InputTemplate {
default: _,
minimum,
maximum,
} => match value.as_f64() {
} => match value.as_f64().map(Into::into) {
Some(value_number) => {
assert_cmp(
&name,
Expand Down Expand Up @@ -705,7 +705,7 @@ impl<'a> ItemTemplate<'a> {
default: _,
minimum,
maximum,
} => match value.as_f64() {
} => match value.as_f64().map(Into::into) {
Some(value_number) => {
assert_cmp(
&name,
Expand Down
2 changes: 1 addition & 1 deletion dash/provider/src/storage/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn convert_field_to_column(
} => {
// attribute: default
if let Some(default) = default {
column.default(*default);
column.default(**default);
}

// attribute: type
Expand Down
10 changes: 5 additions & 5 deletions vine/api/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeMap, ops::Deref, str::FromStr};
use std::{cmp::Ordering, collections::BTreeMap, ops::Deref, str::FromStr};

use chrono::{DateTime, Utc};
use kube::{CustomResource, ResourceExt};
Expand Down Expand Up @@ -96,14 +96,14 @@ impl Deref for EmailAddress {
}

impl PartialOrd for EmailAddress {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0.as_str().partial_cmp(other.0.as_str())
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(<Self as Ord>::cmp(self, other))
}
}

impl Ord for EmailAddress {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.as_str().cmp(other.0.as_str())
fn cmp(&self, other: &Self) -> Ordering {
<str as Ord>::cmp(self.0.as_str(), other.0.as_str())
}
}

Expand Down
10 changes: 5 additions & 5 deletions vine/api/src/user_auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::Deref, str::FromStr};
use std::{cmp::Ordering, ops::Deref, str::FromStr};

use anyhow::{bail, Result};
use k8s_openapi::api::core::v1::NodeSpec;
Expand Down Expand Up @@ -165,14 +165,14 @@ impl Deref for Url {
}

impl PartialOrd for Url {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0.as_str().partial_cmp(other.0.as_str())
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(<Self as Ord>::cmp(self, other))
}
}

impl Ord for Url {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.as_str().cmp(other.0.as_str())
fn cmp(&self, other: &Self) -> Ordering {
<str as Ord>::cmp(self.0.as_str(), other.0.as_str())
}
}

Expand Down
10 changes: 4 additions & 6 deletions vine/bastion/src/routes/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ pub mod login {
Err(response) => Ok(response.into()),
}
} {
Ok(response) if matches!(response, UserSessionResponse::Accept { .. }) => {
Redirect::to("../../")
.temporary()
.respond_to(&request)
.map_into_boxed_body()
}
Ok(UserSessionResponse::Accept { .. }) => Redirect::to("../../")
.temporary()
.respond_to(&request)
.map_into_boxed_body(),
Ok(response) => HttpResponse::Forbidden().json(response),
Err(e) => {
error!("failed to login: {e}");
Expand Down

0 comments on commit ef962c9

Please sign in to comment.