Skip to content

Commit

Permalink
Use #[default] enums, MSRV is 1.78 as of #4008
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoll authored and weiznich committed Mar 3, 2025
1 parent 9f8f806 commit 7c72d21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
10 changes: 2 additions & 8 deletions diesel/src/insertable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ impl<Col, Expr> ColumnInsertValue<Col, Expr> {
}
}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone)]
#[doc(hidden)]
pub enum DefaultableColumnInsertValue<T> {
Expression(T),
#[default]
Default,
}

Expand All @@ -147,13 +148,6 @@ impl<T> QueryId for DefaultableColumnInsertValue<T> {
const HAS_STATIC_QUERY_ID: bool = false;
}

#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
impl<T> Default for DefaultableColumnInsertValue<T> {
fn default() -> Self {
DefaultableColumnInsertValue::Default
}
}

impl<Col, Expr, DB> InsertValues<DB, Col::Table>
for DefaultableColumnInsertValue<ColumnInsertValue<Col, Expr>>
where
Expand Down
10 changes: 2 additions & 8 deletions diesel_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,20 +570,14 @@ impl MigrationsDirectory {

type Regex = RegexWrapper<::regex::Regex>;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub enum Filtering {
OnlyTables(Vec<Regex>),
ExceptTables(Vec<Regex>),
#[default]
None,
}

#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
impl Default for Filtering {
fn default() -> Self {
Filtering::None
}
}

impl Filtering {
pub fn should_ignore_table(&self, name: &TableName) -> bool {
use self::Filtering::*;
Expand Down
30 changes: 6 additions & 24 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,37 @@ use std::str;
const SCHEMA_HEADER: &str = "// @generated automatically by Diesel CLI.\n";

/// How to sort columns when querying the table schema.
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy)]
pub enum ColumnSorting {
/// Order by ordinal position
#[serde(rename = "ordinal_position")]
#[default]
OrdinalPosition,
/// Order by column name
#[serde(rename = "name")]
Name,
}

#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
impl Default for ColumnSorting {
fn default() -> Self {
ColumnSorting::OrdinalPosition
}
}

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
pub enum DocConfig {
DatabaseCommentsFallbackToAutoGeneratedDocComment,
OnlyDatabaseComments,
#[default]
NoDocComments,
}

#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
impl Default for DocConfig {
fn default() -> Self {
DocConfig::NoDocComments
}
}

/// How to group tables in `allow_tables_to_appear_in_same_query!()`.
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy)]
pub enum AllowTablesToAppearInSameQueryConfig {
/// Group by foreign key relations
#[serde(rename = "fk_related_tables")]
FkRelatedTables,
/// List all tables in invocation
#[serde(rename = "all_tables")]
#[default]
AllTables,
}

#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
impl Default for AllowTablesToAppearInSameQueryConfig {
fn default() -> Self {
AllowTablesToAppearInSameQueryConfig::AllTables
}
}

pub fn run_print_schema<W: IoWrite>(
connection: &mut InferConnection,
config: &config::PrintSchema,
Expand Down

0 comments on commit 7c72d21

Please sign in to comment.