Skip to content

Commit 1039f13

Browse files
committed
Clean up BoundSided::side
1 parent b308b90 commit 1039f13

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/impls/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ mod test {
185185

186186
fn test_type<T: PartialEq+FromSql+ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {
187187
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
188-
for &(ref val, ref repr) in checks.iter() {
188+
for &(ref val, ref repr) in checks {
189189
let stmt = conn.prepare(&*format!("SELECT {}::{}", *repr, sql_type)).unwrap();
190190
let result = stmt.query(&[]).unwrap().next().unwrap().get(0);
191191
assert!(val == &result);

src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Types dealing with ranges of values
22
#![doc(html_root_url="https://sfackler.github.io/doc")]
3-
#![feature(io, core)]
3+
#![cfg_attr(test, feature(core))]
4+
#![feature(io)]
45

56
extern crate postgres;
67
extern crate time;
@@ -127,7 +128,7 @@ macro_rules! bounded_normalizable {
127128
($t:ident) => (
128129
impl Normalizable for $t {
129130
fn normalize<S>(bound: RangeBound<S, $t>) -> RangeBound<S, $t> where S: BoundSided {
130-
match (BoundSided::side(None::<S>), bound.type_) {
131+
match (<S as BoundSided>::side(), bound.type_) {
131132
(Upper, Inclusive) => {
132133
assert!(bound.value != $t::MAX);
133134
RangeBound::new(bound.value + 1, Exclusive)
@@ -166,7 +167,7 @@ pub enum BoundSide {
166167
pub trait BoundSided {
167168
/// Returns the bound side this type corresponds to
168169
// param is a hack to get around lack of hints for self type
169-
fn side(_: Option<Self>) -> BoundSide;
170+
fn side() -> BoundSide;
170171
}
171172

172173
/// A tag type representing an upper bound
@@ -178,13 +179,13 @@ pub enum UpperBound {}
178179
pub enum LowerBound {}
179180

180181
impl BoundSided for UpperBound {
181-
fn side(_: Option<UpperBound>) -> BoundSide {
182+
fn side() -> BoundSide {
182183
Upper
183184
}
184185
}
185186

186187
impl BoundSided for LowerBound {
187-
fn side(_: Option<LowerBound>) -> BoundSide {
188+
fn side() -> BoundSide {
188189
Lower
189190
}
190191
}
@@ -226,7 +227,7 @@ impl<S, T> fmt::Debug for RangeBound<S, T> where S: BoundSided, T: fmt::Debug {
226227
Exclusive => ('(', ')'),
227228
};
228229

229-
match BoundSided::side(None::<S>) {
230+
match <S as BoundSided>::side() {
230231
Lower => write!(fmt, "{}{:?}", lower, self.value),
231232
Upper => write!(fmt, "{:?}{}", self.value, upper),
232233
}
@@ -247,7 +248,7 @@ impl<S, T> Eq for RangeBound<S, T> where S: BoundSided, T: Eq {}
247248

248249
impl<S, T> PartialOrd for RangeBound<S, T> where S: BoundSided, T: PartialOrd {
249250
fn partial_cmp(&self, other: &RangeBound<S, T>) -> Option<Ordering> {
250-
match (BoundSided::side(None::<S>), self.type_, other.type_,
251+
match (<S as BoundSided>::side(), self.type_, other.type_,
251252
self.value.partial_cmp(&other.value)) {
252253
(Upper, Exclusive, Inclusive, Some(Ordering::Equal))
253254
| (Lower, Inclusive, Exclusive, Some(Ordering::Equal)) => Some(Ordering::Less),
@@ -260,7 +261,7 @@ impl<S, T> PartialOrd for RangeBound<S, T> where S: BoundSided, T: PartialOrd {
260261

261262
impl<S, T> Ord for RangeBound<S, T> where S: BoundSided, T: Ord {
262263
fn cmp(&self, other: &RangeBound<S, T>) -> Ordering {
263-
match (BoundSided::side(None::<S>), self.type_, other.type_,
264+
match (<S as BoundSided>::side(), self.type_, other.type_,
264265
self.value.cmp(&other.value)) {
265266
(Upper, Exclusive, Inclusive, Ordering::Equal)
266267
| (Lower, Inclusive, Exclusive, Ordering::Equal) => Ordering::Less,
@@ -279,7 +280,7 @@ impl<S, T> RangeBound<S, T> where S: BoundSided, T: PartialOrd {
279280

280281
/// Determines if a value lies within the range specified by this bound.
281282
pub fn in_bounds(&self, value: &T) -> bool {
282-
match (self.type_, BoundSided::side(None::<S>)) {
283+
match (self.type_, <S as BoundSided>::side()) {
283284
(Inclusive, Upper) => value <= &self.value,
284285
(Exclusive, Upper) => value < &self.value,
285286
(Inclusive, Lower) => value >= &self.value,
@@ -304,7 +305,7 @@ impl<'a, S, T> PartialEq for OptBound<'a, S, T> where S: BoundSided, T: PartialE
304305

305306
impl<'a, S, T> PartialOrd for OptBound<'a, S, T> where S: BoundSided, T: PartialOrd {
306307
fn partial_cmp(&self, other: &OptBound<'a, S, T>) -> Option<Ordering> {
307-
match (self, other, BoundSided::side(None::<S>)) {
308+
match (self, other, <S as BoundSided>::side()) {
308309
(&OptBound(None), &OptBound(None), _) => Some(Ordering::Equal),
309310
(&OptBound(None), _, Lower)
310311
| (_, &OptBound(None), Upper) => Some(Ordering::Less),

0 commit comments

Comments
 (0)