Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new Clippy lints under rustc 1.68.0: derivable defaults and manual character checks #485

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [#480](https://github.com/thoth-pub/thoth/pull/480) Add field to work table to track when the work or any of its relations was last updated

### Changed
- Removed manual character checks and derivable defaults to comply with [`rustc 1.68.0`](https://github.com/rust-lang/rust/releases/tag/1.68.0)

## [[0.9.15]](https://github.com/thoth-pub/thoth/releases/tag/v0.9.15) - 2023-03-01
### Fixed
- Issue adding institutions in previous release
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/graphql/utils.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use serde::Deserialize;
use serde::Serialize;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, juniper::GraphQLEnum)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, juniper::GraphQLEnum)]
#[graphql(description = "Order in which to sort query results (ascending or descending)")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Direction {
#[default]
Asc,
Desc,
}

impl Default for Direction {
fn default() -> Direction {
Direction::Asc
}
}

#[test]
fn test_direction_default() {
let dir: Direction = Default::default();
Expand Down
11 changes: 4 additions & 7 deletions thoth-api/src/model/contribution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ use crate::schema::contribution_history;
graphql(description = "Role describing the type of contribution to the work"),
DieselTypePath = "crate::schema::sql_types::ContributionType"
)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(
Debug, Clone, Default, Copy, PartialEq, Eq, Deserialize, Serialize, EnumString, Display,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "title_case")]
pub enum ContributionType {
#[cfg_attr(feature = "backend", graphql(description = "Author of the work"))]
#[default]
Author,
#[cfg_attr(feature = "backend", graphql(description = "Editor of the work"))]
Editor,
Expand Down Expand Up @@ -202,12 +205,6 @@ pub struct NewContributionHistory {
pub data: serde_json::Value,
}

impl Default for ContributionType {
fn default() -> ContributionType {
ContributionType::Author
}
}

impl Default for Contribution {
fn default() -> Contribution {
Contribution {
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/contributor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ use crate::schema::contributor_history;
derive(juniper::GraphQLEnum),
graphql(description = "Field to use when sorting contributors list")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ContributorField {
#[strum(serialize = "ID")]
ContributorId,
FirstName,
LastName,
#[default]
FullName,
#[serde(rename = "ORCID")]
#[strum(serialize = "ORCID")]
Expand Down Expand Up @@ -106,12 +107,6 @@ pub struct ContributorOrderBy {
pub direction: Direction,
}

impl Default for ContributorField {
fn default() -> Self {
ContributorField::FullName
}
}

impl fmt::Display for Contributor {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(orcid) = &self.orcid {
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/imprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ use crate::schema::imprint_history;
derive(juniper::GraphQLEnum),
graphql(description = "Field to use when sorting imprints list")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ImprintField {
#[strum(serialize = "ID")]
ImprintId,
#[strum(serialize = "Imprint")]
#[default]
ImprintName,
#[strum(serialize = "ImprintURL")]
ImprintUrl,
Expand Down Expand Up @@ -106,12 +107,6 @@ pub struct ImprintOrderBy {
pub direction: Direction,
}

impl Default for ImprintField {
fn default() -> Self {
ImprintField::ImprintName
}
}

#[test]
fn test_imprintfield_default() {
let impfield: ImprintField = Default::default();
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/institution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ use crate::schema::institution_history;
derive(juniper::GraphQLEnum),
graphql(description = "Field to use when sorting institutions list")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum InstitutionField {
#[strum(serialize = "ID")]
InstitutionId,
#[strum(serialize = "Institution")]
#[default]
InstitutionName,
#[strum(serialize = "DOI")]
InstitutionDoi,
Expand Down Expand Up @@ -613,12 +614,6 @@ pub struct InstitutionOrderBy {
pub direction: Direction,
}

impl Default for InstitutionField {
fn default() -> Self {
InstitutionField::InstitutionName
}
}

impl fmt::Display for Institution {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(ror) = &self.ror {
Expand Down
18 changes: 4 additions & 14 deletions thoth-api/src/model/language/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use crate::schema::language_history;
derive(DbEnum, juniper::GraphQLEnum),
DieselTypePath = "crate::schema::sql_types::LanguageRelation"
)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "title_case")]
pub enum LanguageRelation {
#[default]
Original,
#[cfg_attr(feature = "backend", db_rename = "translated-from")]
TranslatedFrom,
Expand Down Expand Up @@ -83,7 +84,7 @@ pub struct PatchLanguage {
derive(DbEnum, juniper::GraphQLEnum),
DieselTypePath = "crate::schema::sql_types::LanguageCode"
)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "UPPERCASE")]
pub enum LanguageCode {
Expand Down Expand Up @@ -210,6 +211,7 @@ pub enum LanguageCode {
Egy,
Eka,
Elx,
#[default]
Eng,
Enm,
Epo,
Expand Down Expand Up @@ -596,18 +598,6 @@ pub struct NewLanguageHistory {
pub data: serde_json::Value,
}

impl Default for LanguageCode {
fn default() -> LanguageCode {
LanguageCode::Eng
}
}

impl Default for LanguageRelation {
fn default() -> LanguageRelation {
LanguageRelation::Original
}
}

impl Default for Language {
fn default() -> Language {
Language {
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::schema::location_history;
derive(DbEnum, juniper::GraphQLEnum),
DieselTypePath = "crate::schema::sql_types::LocationPlatform"
)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum LocationPlatform {
#[cfg_attr(feature = "backend", db_rename = "Project MUSE")]
Expand Down Expand Up @@ -49,6 +49,7 @@ pub enum LocationPlatform {
#[strum(serialize = "JISC KB")]
JiscKb,
#[cfg_attr(feature = "backend", db_rename = "Other")]
#[default]
Other,
}

Expand Down Expand Up @@ -139,12 +140,6 @@ pub struct LocationOrderBy {
pub direction: Direction,
}

impl Default for LocationPlatform {
fn default() -> LocationPlatform {
LocationPlatform::Other
}
}

#[test]
fn test_locationplatform_default() {
let locationplatform: LocationPlatform = Default::default();
Expand Down
18 changes: 4 additions & 14 deletions thoth-api/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ pub const ROR_DOMAIN: &str = "https://ror.org/";
derive(juniper::GraphQLEnum),
graphql(description = "Unit of measurement for physical Work dimensions (mm, cm or in)")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "lowercase")]
pub enum LengthUnit {
#[default]
Mm,
Cm,
In,
Expand All @@ -32,10 +33,11 @@ pub enum LengthUnit {
derive(juniper::GraphQLEnum),
graphql(description = "Unit of measurement for physical Work weight (grams or ounces)")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "lowercase")]
pub enum WeightUnit {
#[default]
G,
Oz,
}
Expand Down Expand Up @@ -88,18 +90,6 @@ pub struct Ror(String);
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Timestamp(DateTime<Utc>);

impl Default for LengthUnit {
fn default() -> LengthUnit {
LengthUnit::Mm
}
}

impl Default for WeightUnit {
fn default() -> WeightUnit {
WeightUnit::G
}
}

impl Default for Timestamp {
fn default() -> Timestamp {
Timestamp(TimeZone::timestamp_opt(&Utc, 0, 0).unwrap())
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/price/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct PatchPrice {
derive(DbEnum, juniper::GraphQLEnum),
DieselTypePath = "crate::schema::sql_types::CurrencyCode"
)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "UPPERCASE")]
pub enum CurrencyCode {
Expand Down Expand Up @@ -161,6 +161,7 @@ pub enum CurrencyCode {
Fjd,
Fkp,
Frf,
#[default]
Gbp,
Gek,
Gel,
Expand Down Expand Up @@ -387,12 +388,6 @@ pub struct NewPriceHistory {
pub data: serde_json::Value,
}

impl Default for CurrencyCode {
fn default() -> CurrencyCode {
CurrencyCode::Gbp
}
}

#[test]
fn test_currencycode_default() {
let currencycode: CurrencyCode = Default::default();
Expand Down
18 changes: 4 additions & 14 deletions thoth-api/src/model/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ use crate::schema::publication_history;
derive(DbEnum, juniper::GraphQLEnum),
DieselTypePath = "crate::schema::sql_types::PublicationType"
)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PublicationType {
#[cfg_attr(feature = "backend", db_rename = "Paperback")]
#[default]
Paperback,
#[cfg_attr(feature = "backend", db_rename = "Hardback")]
Hardback,
Expand Down Expand Up @@ -55,12 +56,13 @@ pub enum PublicationType {
derive(juniper::GraphQLEnum),
graphql(description = "Field to use when sorting publications list")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PublicationField {
#[strum(serialize = "ID")]
PublicationId,
#[strum(serialize = "Type")]
#[default]
PublicationType,
#[strum(serialize = "WorkID")]
WorkId,
Expand Down Expand Up @@ -446,18 +448,6 @@ impl PublicationProperties for PatchPublication {
}
}

impl Default for PublicationType {
fn default() -> PublicationType {
PublicationType::Paperback
}
}

impl Default for PublicationField {
fn default() -> Self {
PublicationField::PublicationType
}
}

#[test]
fn test_publicationproperties_type() {
let mut publication: Publication = Default::default();
Expand Down
9 changes: 2 additions & 7 deletions thoth-api/src/model/publisher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ use crate::schema::publisher_history;
derive(juniper::GraphQLEnum),
graphql(description = "Field to use when sorting publishers list")
)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PublisherField {
#[strum(serialize = "ID")]
PublisherId,
#[strum(serialize = "Name")]
#[default]
PublisherName,
#[strum(serialize = "ShortName")]
PublisherShortname,
Expand Down Expand Up @@ -97,12 +98,6 @@ pub struct PublisherOrderBy {
pub direction: Direction,
}

impl Default for PublisherField {
fn default() -> Self {
PublisherField::PublisherName
}
}

impl fmt::Display for Publisher {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.publisher_name)
Expand Down
Loading