Skip to content

Commit 4c6d29d

Browse files
committed
Replaced eq_shallow with matches!
1 parent 010db5d commit 4c6d29d

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

src/create_column.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,27 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
177177

178178
match d.data_type {
179179
DbType::VarChar => {
180-
let a_opt = d
180+
let max_length = d
181181
.annotations
182182
.iter()
183-
.find(|x| x.annotation.eq_shallow(&Annotation::MaxLength(0)));
184-
185-
if let Some(a) = a_opt {
186-
if let Annotation::MaxLength(max_length) = a.annotation {
187-
write!(s, "character varying ({max_length}) ").unwrap();
188-
} else {
189-
return Err(Error::SQLBuildError(
183+
.find_map(|x| match x.annotation {
184+
Annotation::MaxLength(x) => Some(*x),
185+
_ => None,
186+
})
187+
.ok_or_else(|| {
188+
Error::SQLBuildError(
190189
"character varying must have a max_length annotation"
191190
.to_string(),
192-
));
193-
}
194-
} else {
195-
return Err(Error::SQLBuildError(
196-
"character varying must have a max_length annotation".to_string(),
197-
));
198-
}
191+
)
192+
})?;
193+
194+
write!(s, "character varying ({max_length}) ").unwrap();
199195
}
200196
DbType::Choices => {
201-
let a_opt = d.annotations.iter().find(|x| {
202-
x.annotation
203-
.eq_shallow(&Annotation::Choices(Default::default()))
204-
});
197+
let a_opt = d
198+
.annotations
199+
.iter()
200+
.find(|x| matches!(x.annotation, Annotation::Choices(_)));
205201

206202
if let Some(a) = a_opt {
207203
if let Annotation::Choices(values) = a.annotation {
@@ -241,7 +237,7 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
241237
DbType::Int16 => {
242238
if d.annotations
243239
.iter()
244-
.any(|x| x.annotation.eq_shallow(&Annotation::AutoIncrement))
240+
.any(|x| matches!(x.annotation, Annotation::AutoIncrement))
245241
{
246242
write!(s, "smallserial ").unwrap();
247243
} else {
@@ -251,7 +247,7 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
251247
DbType::Int32 => {
252248
if d.annotations
253249
.iter()
254-
.any(|x| x.annotation.eq_shallow(&Annotation::AutoIncrement))
250+
.any(|x| matches!(x.annotation, Annotation::AutoIncrement))
255251
{
256252
write!(s, "serial ").unwrap();
257253
} else {
@@ -261,7 +257,7 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
261257
DbType::Int64 => {
262258
if d.annotations
263259
.iter()
264-
.any(|x| x.annotation.eq_shallow(&Annotation::AutoIncrement))
260+
.any(|x| matches!(x.annotation, Annotation::AutoIncrement))
265261
{
266262
write!(s, "bigserial ").unwrap();
267263
} else {

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ impl DBImpl {
249249
let mut a = vec![];
250250

251251
for x in annotations {
252-
if x.eq_shallow(&Annotation::PrimaryKey) {
252+
if matches!(x, Annotation::PrimaryKey) {
253253
a.push(SQLAnnotation { annotation: x });
254254
}
255255
}
256256

257257
for x in annotations {
258-
if !x.eq_shallow(&Annotation::PrimaryKey) {
258+
if !matches!(x, Annotation::PrimaryKey) {
259259
a.push(SQLAnnotation { annotation: x });
260260
}
261261
}

0 commit comments

Comments
 (0)