Skip to content

Commit e2342ac

Browse files
committed
Use Rust 2018 syntax & ensure code follows up-to-date idioms
1 parent 95f901a commit e2342ac

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "postgres_range"
33
version = "0.9.1"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
5+
edition = "2018"
56
license = "MIT"
67
description = "Range support for rust-postgres"
78
repository = "https://github.com/sfackler/rust-postgres-range"

src/impls.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use postgres_types::{FromSql, IsNull, Kind, ToSql, Type};
33
use postgres_types::private::BytesMut;
44
use postgres_protocol::{self as protocol, types};
55

6-
use {BoundSided, BoundType, Normalizable, Range, RangeBound};
6+
use crate::{BoundSided, BoundType, Normalizable, Range, RangeBound};
77

88
impl<'a, T> FromSql<'a> for Range<T>
99
where
1010
T: PartialOrd + Normalizable + FromSql<'a>,
1111
{
1212
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Range<T>, Box<dyn Error + Sync + Send>> {
13-
let element_type = match ty.kind() {
14-
&Kind::Range(ref ty) => ty,
13+
let element_type = match *ty.kind() {
14+
Kind::Range(ref ty) => ty,
1515
_ => panic!("unexpected type {:?}", ty),
1616
};
1717

@@ -26,8 +26,8 @@ where
2626
}
2727

2828
fn accepts(ty: &Type) -> bool {
29-
match ty.kind() {
30-
&Kind::Range(ref inner) => <T as FromSql>::accepts(inner),
29+
match *ty.kind() {
30+
Kind::Range(ref inner) => <T as FromSql>::accepts(inner),
3131
_ => false,
3232
}
3333
}
@@ -62,8 +62,8 @@ where
6262
T: PartialOrd + Normalizable + ToSql,
6363
{
6464
fn to_sql(&self, ty: &Type, buf: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
65-
let element_type = match ty.kind() {
66-
&Kind::Range(ref ty) => ty,
65+
let element_type = match *ty.kind() {
66+
Kind::Range(ref ty) => ty,
6767
_ => panic!("unexpected type {:?}", ty),
6868
};
6969

@@ -81,8 +81,8 @@ where
8181
}
8282

8383
fn accepts(ty: &Type) -> bool {
84-
match ty.kind() {
85-
&Kind::Range(ref inner) => <T as ToSql>::accepts(inner),
84+
match *ty.kind() {
85+
Kind::Range(ref inner) => <T as ToSql>::accepts(inner),
8686
_ => false,
8787
}
8888
}

src/lib.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
//! Types dealing with ranges of values
22
#![doc(html_root_url = "https://sfackler.github.io/rust-postgres-range/doc/v0.9")]
3+
#![warn(clippy::all, rust_2018_idioms, missing_docs)]
34

4-
extern crate postgres_protocol;
55
#[macro_use(to_sql_checked)]
66
extern crate postgres_types;
77

88
#[cfg(feature = "with-chrono-0_4")]
99
mod chrono_04;
1010

11-
#[cfg(test)]
12-
extern crate postgres;
13-
1411
use std::cmp::Ordering;
1512
use std::fmt;
1613
use std::i32;
@@ -222,7 +219,7 @@ where
222219
fn clone(&self) -> RangeBound<S, T> {
223220
RangeBound {
224221
value: self.value.clone(),
225-
type_: self.type_.clone(),
222+
type_: self.type_,
226223
_m: PhantomData,
227224
}
228225
}
@@ -233,7 +230,7 @@ where
233230
S: BoundSided,
234231
T: fmt::Debug,
235232
{
236-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
233+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
237234
fmt.debug_struct("RangeBound")
238235
.field("value", &self.value)
239236
.field("type_", &self.type_)
@@ -246,7 +243,7 @@ where
246243
S: BoundSided,
247244
T: fmt::Display,
248245
{
249-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
246+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
250247
let (lower, upper) = match self.type_ {
251248
Inclusive => ('[', ']'),
252249
Exclusive => ('(', ')'),
@@ -268,9 +265,9 @@ where
268265
self.value == other.value && self.type_ == other.type_
269266
}
270267

271-
fn ne(&self, other: &RangeBound<S, T>) -> bool {
268+
/*fn ne(&self, other: &RangeBound<S, T>) -> bool {
272269
self.value != other.value || self.type_ != other.type_
273-
}
270+
}*/
274271
}
275272

276273
impl<S, T> Eq for RangeBound<S, T>
@@ -326,8 +323,8 @@ where
326323
/// Constructs a new range bound
327324
pub fn new(value: T, type_: BoundType) -> RangeBound<S, T> {
328325
RangeBound {
329-
value: value,
330-
type_: type_,
326+
value,
327+
type_,
331328
_m: PhantomData,
332329
}
333330
}
@@ -343,7 +340,7 @@ where
343340
}
344341
}
345342

346-
struct OptBound<'a, S: 'a + BoundSided, T: 'a>(Option<&'a RangeBound<S, T>>);
343+
struct OptBound<'a, S: BoundSided, T>(Option<&'a RangeBound<S, T>>);
347344

348345
impl<'a, S, T> PartialEq for OptBound<'a, S, T>
349346
where
@@ -355,10 +352,10 @@ where
355352
self_ == other
356353
}
357354

358-
fn ne(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {
355+
/*fn ne(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {
359356
let &OptBound(ref self_) = self;
360357
self_ != other
361-
}
358+
}*/
362359
}
363360

364361
impl<'a, S, T> PartialOrd for OptBound<'a, S, T>
@@ -395,7 +392,7 @@ impl<T> fmt::Display for Range<T>
395392
where
396393
T: fmt::Display,
397394
{
398-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
395+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
399396
match self.inner {
400397
Empty => write!(fmt, "empty"),
401398
Normal(ref lower, ref upper) => {
@@ -520,7 +517,7 @@ where
520517
let (_, OptBound(lower)) = order(OptBound(self.lower()), OptBound(other.lower()));
521518
let (OptBound(upper), _) = order(OptBound(self.upper()), OptBound(other.upper()));
522519

523-
Range::new(lower.map(|v| v.clone()), upper.map(|v| v.clone()))
520+
Range::new(lower.cloned(), upper.cloned())
524521
}
525522

526523
/// Returns the union of this range with another if it is contiguous.
@@ -557,8 +554,8 @@ where
557554
None
558555
} else {
559556
Some(Range::new(
560-
l_lower.map(|v| v.clone()),
561-
u_upper.map(|v| v.clone()),
557+
l_lower.cloned(),
558+
u_upper.cloned(),
562559
))
563560
}
564561
}
@@ -720,7 +717,7 @@ mod test {
720717
assert_eq!(r1, (range!('(',; ')')).intersect(&r1));
721718

722719
let r2 = range!('(' 10i32,; ')');
723-
let exp = Range::new(r2.lower().map(|v| v.clone()), r1.upper().map(|v| v.clone()));
720+
let exp = Range::new(r2.lower().copied(), r1.upper().copied());
724721
assert_eq!(exp, r1.intersect(&r2));
725722
assert_eq!(exp, r2.intersect(&r1));
726723

0 commit comments

Comments
 (0)