|
4 | 4 | extern crate extra; |
5 | 5 |
|
6 | 6 | use std::cmp; |
| 7 | +use std::fmt; |
7 | 8 | use std::i32; |
8 | 9 | use std::i64; |
9 | 10 | use time::Timespec; |
@@ -179,6 +180,26 @@ pub struct RangeBound<S, T> { |
179 | 180 | type_: BoundType |
180 | 181 | } |
181 | 182 |
|
| 183 | +impl<S: BoundSided, T: fmt::Show> fmt::Show for RangeBound<S, T> { |
| 184 | + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 185 | + let chars = match self.type_ { |
| 186 | + Inclusive => ['[', ']'], |
| 187 | + Exclusive => ['(', ')'], |
| 188 | + }; |
| 189 | + |
| 190 | + match BoundSided::side(None::<S>) { |
| 191 | + Lower => { |
| 192 | + try!(formatter.buf.write_char(chars[0])); |
| 193 | + self.value.fmt(formatter) |
| 194 | + } |
| 195 | + Upper => { |
| 196 | + try!(self.value.fmt(formatter)); |
| 197 | + formatter.buf.write_char(chars[1]) |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | +} |
| 202 | + |
182 | 203 | impl<S: BoundSided, T: Ord> Ord for RangeBound<S, T> { |
183 | 204 | fn lt(&self, other: &RangeBound<S, T>) -> bool { |
184 | 205 | match (BoundSided::side(None::<S>), self.type_, other.type_) { |
@@ -227,6 +248,25 @@ pub enum Range<T> { |
227 | 248 | Option<RangeBound<UpperBound, T>>) |
228 | 249 | } |
229 | 250 |
|
| 251 | +impl<T: fmt::Show> fmt::Show for Range<T> { |
| 252 | + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 253 | + match *self { |
| 254 | + Empty => formatter.buf.write_str("empty"), |
| 255 | + Normal(ref lower, ref upper) => { |
| 256 | + match *lower { |
| 257 | + Some(ref bound) => try!(bound.fmt(formatter)), |
| 258 | + None => try!(formatter.buf.write_char('(')), |
| 259 | + } |
| 260 | + try!(formatter.buf.write_char(',')); |
| 261 | + match *upper { |
| 262 | + Some(ref bound) => bound.fmt(formatter), |
| 263 | + None => formatter.buf.write_char(')'), |
| 264 | + } |
| 265 | + } |
| 266 | + } |
| 267 | + } |
| 268 | +} |
| 269 | + |
230 | 270 | impl<T: Ord+Normalizable> Range<T> { |
231 | 271 | /// Creates a new range. |
232 | 272 | /// |
|
0 commit comments