Skip to content

Commit 277f3f9

Browse files
committed
Merge branch 'release-v0.7.4' into release
2 parents 7251798 + ae8bd6e commit 277f3f9

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[package]
22
name = "postgres_range"
3-
version = "0.7.3"
3+
version = "0.7.4"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
license = "MIT"
66
description = "Range support for rust-postgres"
77
repository = "https://github.com/sfackler/rust-postgres-range"
8-
documentation = "https://sfackler.github.io/rust-postgres-range/doc/v0.7.3/postgres_range"
8+
documentation = "https://sfackler.github.io/rust-postgres-range/doc/v0.7.4/postgres_range"
99

1010
[dependencies]
1111
time = "0.1"
1212
postgres = ">= 0.9, < 0.11"
13-
byteorder = "0.3"
13+
byteorder = ">= 0.3, < 0.5"
1414

1515
[dev-dependencies.postgres]
1616
features = ["time"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# rust-postgres-range
22
[![Build Status](https://travis-ci.org/sfackler/rust-postgres-range.svg?branch=master)](https://travis-ci.org/sfackler/rust-postgres-range)
33

4-
[Documentation](https://sfackler.github.io/rust-postgres-range/doc/v0.7.3/postgres_range)
4+
[Documentation](https://sfackler.github.io/rust-postgres-range/doc/v0.7.4/postgres_range)
55

66
Support for PostgreSQL ranges in [rust-postgres](https://github.com/sfackler/rust-postgres).

src/lib.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Types dealing with ranges of values
2-
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-range/doc/v0.7.3")]
2+
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-range/doc/v0.7.4")]
33

44
#[macro_use(to_sql_checked)]
55
extern crate postgres;
@@ -109,7 +109,7 @@ macro_rules! range {
109109
mod impls;
110110

111111
/// A trait that normalizes a range bound for a type
112-
pub trait Normalizable {
112+
pub trait Normalizable: Sized {
113113
/// Given a range bound, returns the normalized version of that bound. For
114114
/// discrete types such as i32, the normalized lower bound is always
115115
/// inclusive and the normalized upper bound is always exclusive. Other
@@ -150,27 +150,25 @@ impl Normalizable for Timespec {
150150
}
151151
}
152152

153-
/// The possible sides of a bound
154-
#[derive(PartialEq, Eq, Clone, Copy)]
153+
/// The possible sides of a bound.
154+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
155155
pub enum BoundSide {
156-
/// An upper bound
156+
/// An upper bound.
157157
Upper,
158-
/// A lower bound
158+
/// A lower bound.
159159
Lower
160160
}
161161

162-
/// A trait implemented by phantom types indicating the type of the bound
162+
/// A trait implemented by phantom types indicating the type of the bound.
163163
pub trait BoundSided {
164-
/// Returns the bound side this type corresponds to
164+
/// Returns the bound side this type corresponds to.
165165
fn side() -> BoundSide;
166166
}
167167

168168
/// A tag type representing an upper bound
169-
#[allow(missing_copy_implementations)]
170169
pub enum UpperBound {}
171170

172171
/// A tag type representing a lower bound
173-
#[allow(missing_copy_implementations)]
174172
pub enum LowerBound {}
175173

176174
impl BoundSided for UpperBound {
@@ -185,22 +183,22 @@ impl BoundSided for LowerBound {
185183
}
186184
}
187185

188-
/// The type of a range bound
189-
#[derive(PartialEq, Eq, Clone, Copy)]
186+
/// The type of a range bound.
187+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
190188
pub enum BoundType {
191-
/// The bound includes its value
189+
/// The bound includes its value.
192190
Inclusive,
193-
/// The bound excludes its value
191+
/// The bound excludes its value.
194192
Exclusive
195193
}
196194

197195
/// Represents a one-sided bound.
198196
///
199197
/// The side is determined by the `S` phantom parameter.
200198
pub struct RangeBound<S: BoundSided, T> {
201-
/// The value of the bound
199+
/// The value of the bound.
202200
pub value: T,
203-
/// The type of the bound
201+
/// The type of the bound.
204202
pub type_: BoundType,
205203
_m: PhantomData<*mut S>,
206204
}
@@ -218,15 +216,24 @@ impl<S, T> Clone for RangeBound<S, T> where S: BoundSided, T: Clone {
218216
}
219217

220218
impl<S, T> fmt::Debug for RangeBound<S, T> where S: BoundSided, T: fmt::Debug {
219+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
220+
fmt.debug_struct("RangeBound")
221+
.field("value", &self.value)
222+
.field("type_", &self.type_)
223+
.finish()
224+
}
225+
}
226+
227+
impl<S, T> fmt::Display for RangeBound<S, T> where S: BoundSided, T: fmt::Display {
221228
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
222229
let (lower, upper) = match self.type_ {
223230
Inclusive => ('[', ']'),
224231
Exclusive => ('(', ')'),
225232
};
226233

227234
match <S as BoundSided>::side() {
228-
Lower => write!(fmt, "{}{:?}", lower, self.value),
229-
Upper => write!(fmt, "{:?}{}", self.value, upper),
235+
Lower => write!(fmt, "{}{}", lower, self.value),
236+
Upper => write!(fmt, "{}{}", self.value, upper),
230237
}
231238
}
232239
}
@@ -290,7 +297,7 @@ impl<S, T> RangeBound<S, T> where S: BoundSided, T: PartialOrd {
290297
}
291298
}
292299

293-
struct OptBound<'a, S: 'a+BoundSided, T:'a>(Option<&'a RangeBound<S, T>>);
300+
struct OptBound<'a, S: 'a + BoundSided, T:'a>(Option<&'a RangeBound<S, T>>);
294301

295302
impl<'a, S, T> PartialEq for OptBound<'a, S, T> where S: BoundSided, T: PartialEq {
296303
fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {
@@ -318,38 +325,38 @@ impl<'a, S, T> PartialOrd for OptBound<'a, S, T> where S: BoundSided, T: Partial
318325
}
319326

320327
/// Represents a range of values.
321-
#[derive(PartialEq, Eq, Clone, Copy)]
328+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
322329
pub struct Range<T> {
323330
inner: InnerRange<T>,
324331
}
325332

326-
#[derive(PartialEq, Eq, Clone, Copy)]
333+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
327334
enum InnerRange<T> {
328335
Empty,
329336
Normal(Option<RangeBound<LowerBound, T>>,
330337
Option<RangeBound<UpperBound, T>>)
331338
}
332339

333-
impl<T> fmt::Debug for Range<T> where T: fmt::Debug {
340+
impl<T> fmt::Display for Range<T> where T: fmt::Display {
334341
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
335342
match self.inner {
336343
Empty => write!(fmt, "empty"),
337344
Normal(ref lower, ref upper) => {
338345
match *lower {
339-
Some(ref bound) => try!(write!(fmt, "{:?}", bound)),
346+
Some(ref bound) => try!(write!(fmt, "{}", bound)),
340347
None => try!(write!(fmt, "(")),
341348
}
342349
try!(write!(fmt, ","));
343350
match *upper {
344-
Some(ref bound) => write!(fmt, "{:?}", bound),
351+
Some(ref bound) => write!(fmt, "{}", bound),
345352
None => write!(fmt, ")"),
346353
}
347354
}
348355
}
349356
}
350357
}
351358

352-
impl<T> Range<T> where T: PartialOrd+Normalizable{
359+
impl<T> Range<T> where T: PartialOrd + Normalizable {
353360
/// Creates a new range.
354361
///
355362
/// If a bound is `None`, the range is unbounded in that direction.
@@ -435,7 +442,7 @@ fn order<T>(a: T, b: T) -> (T, T) where T: PartialOrd {
435442
}
436443

437444
impl<T> Range<T> where T: PartialOrd+Normalizable+Clone {
438-
/// Returns the intersection of this range with another
445+
/// Returns the intersection of this range with another.
439446
pub fn intersect(&self, other: &Range<T>) -> Range<T> {
440447
if self.is_empty() || other.is_empty() {
441448
return Range::empty();
@@ -449,7 +456,7 @@ impl<T> Range<T> where T: PartialOrd+Normalizable+Clone {
449456
Range::new(lower.map(|v| v.clone()), upper.map(|v| v.clone()))
450457
}
451458

452-
/// Returns the union of this range with another if it is contiguous
459+
/// Returns the union of this range with another if it is contiguous.
453460
pub fn union(&self, other: &Range<T>) -> Option<Range<T>> {
454461
if self.is_empty() {
455462
return Some(other.clone());

0 commit comments

Comments
 (0)