Skip to content

Commit fc6b65d

Browse files
authored
Add non_exhaustive to enums (#891)
* Add `non_exhaustive` to `SimpleExpr` * Add `non_exhasutive` to more enum - func::Function - types::{ColumnRef, TableRef, UnOper, BinOper, Keyword, SubQueryOper} - value::{Value, ValueTuple} - extension::mysql::column::MySqlType - extension::postgres::func::PgFunction - extension::postgres::PgBinOper - extension::postgres::select::SampleMethod - extension::postgres::types::TypeAs - extension::sqlite::SqliteBinOper * Add `non_exhasutive` to more enum * Add helper functions
1 parent ff7c221 commit fc6b65d

File tree

26 files changed

+108
-0
lines changed

26 files changed

+108
-0
lines changed

src/backend/foreign_key_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::*;
22

33
#[derive(Debug, PartialEq, Eq)]
4+
#[non_exhaustive]
45
pub enum Mode {
56
Creation,
67
Alter,

src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub type Expr = SimpleExpr;
2828
/// [`Func::cust`], or [`Expr::cust*`][`Expr::cust_with_values`] as a
2929
/// workaround, and consider reporting your issue.
3030
#[derive(Debug, Clone, PartialEq)]
31+
#[non_exhaustive]
3132
pub enum SimpleExpr {
3233
Column(ColumnRef),
3334
Tuple(Vec<SimpleExpr>),

src/extension/mysql/column.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::Iden;
22

33
#[derive(Debug, Copy, Clone)]
4+
#[non_exhaustive]
45
pub enum MySqlType {
56
TinyBlob,
67
MediumBlob,

src/extension/mysql/index.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ pub struct IndexHint {
1010
}
1111

1212
#[derive(Debug, Clone, Copy, PartialEq)]
13+
#[non_exhaustive]
1314
pub enum IndexHintType {
1415
Use,
1516
Ignore,
1617
Force,
1718
}
1819

1920
#[derive(Debug, Clone, Copy, PartialEq)]
21+
#[non_exhaustive]
2022
pub enum IndexHintScope {
2123
Join,
2224
OrderBy,

src/extension/postgres/func.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{PgDateTruncUnit, expr::*, func::*};
88
///
99
/// If something is not supported, you can use [`Function::Custom`].
1010
#[derive(Debug, Clone, PartialEq)]
11+
#[non_exhaustive]
1112
pub enum PgFunction {
1213
ToTsquery,
1314
ToTsvector,

src/extension/postgres/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) mod types;
1919
///
2020
/// For all supported operators (including the standard ones), see [`BinOper`].
2121
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22+
#[non_exhaustive]
2223
pub enum PgBinOper {
2324
ILike,
2425
NotILike,

src/extension/postgres/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct TableSample {
88
}
99

1010
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11+
#[non_exhaustive]
1112
pub enum SampleMethod {
1213
BERNOULLI,
1314
SYSTEM,

src/extension/postgres/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{QueryBuilder, QuotedBuilder, prepare::*, types::*};
55
pub struct Type;
66

77
#[derive(Clone, Debug)]
8+
#[non_exhaustive]
89
pub enum TypeRef {
910
Type(DynIden),
1011
SchemaType(DynIden, DynIden),
@@ -59,6 +60,7 @@ pub struct TypeCreateStatement {
5960
}
6061

6162
#[derive(Debug, Clone)]
63+
#[non_exhaustive]
6264
pub enum TypeAs {
6365
// Composite,
6466
Enum,
@@ -81,12 +83,14 @@ pub struct TypeAlterStatement {
8183
}
8284

8385
#[derive(Debug, Clone)]
86+
#[non_exhaustive]
8487
pub enum TypeDropOpt {
8588
Cascade,
8689
Restrict,
8790
}
8891

8992
#[derive(Debug, Clone)]
93+
#[non_exhaustive]
9094
pub enum TypeAlterOpt {
9195
Add {
9296
value: DynIden,
@@ -98,6 +102,7 @@ pub enum TypeAlterOpt {
98102
}
99103

100104
#[derive(Debug, Clone)]
105+
#[non_exhaustive]
101106
pub enum TypeAlterAddOpt {
102107
Before(DynIden),
103108
After(DynIden),

src/extension/sqlite/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod expr;
88
///
99
/// For all supported operators (including the standard ones), see [`BinOper`].
1010
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11+
#[non_exhaustive]
1112
pub enum SqliteBinOper {
1213
/// `GLOB`
1314
Glob,

src/foreign_key/common.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct TableForeignKey {
1414

1515
/// Foreign key on update & on delete actions
1616
#[derive(Debug, Clone, Copy)]
17+
#[non_exhaustive]
1718
pub enum ForeignKeyAction {
1819
Restrict,
1920
Cascade,
@@ -22,6 +23,20 @@ pub enum ForeignKeyAction {
2223
SetDefault,
2324
}
2425

26+
impl ForeignKeyAction {
27+
#[doc(hidden)]
28+
/// Return the PascalCase name of the action
29+
pub fn variant_name(&self) -> &'static str {
30+
match self {
31+
Self::Restrict => "Restrict",
32+
Self::Cascade => "Cascade",
33+
Self::SetNull => "SetNull",
34+
Self::NoAction => "NoAction",
35+
Self::SetDefault => "SetDefault",
36+
}
37+
}
38+
}
39+
2540
impl TableForeignKey {
2641
/// Construct a new foreign key
2742
pub fn new() -> Self {

0 commit comments

Comments
 (0)