|
145 | 145 | #![stable(feature = "rust1", since = "1.0.0")]
|
146 | 146 |
|
147 | 147 | use clone::Clone;
|
148 |
| -use cmp::{PartialEq, Eq}; |
| 148 | +use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; |
149 | 149 | use default::Default;
|
150 | 150 | use marker::{Copy, Send, Sync, Sized, Unsize};
|
151 | 151 | use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized};
|
@@ -279,6 +279,42 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
|
279 | 279 | #[stable(feature = "cell_eq", since = "1.2.0")]
|
280 | 280 | impl<T:Eq + Copy> Eq for Cell<T> {}
|
281 | 281 |
|
| 282 | +#[stable(feature = "cell_ord", since = "1.10.0")] |
| 283 | +impl<T:PartialOrd + Copy> PartialOrd for Cell<T> { |
| 284 | + #[inline] |
| 285 | + fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> { |
| 286 | + self.get().partial_cmp(&other.get()) |
| 287 | + } |
| 288 | + |
| 289 | + #[inline] |
| 290 | + fn lt(&self, other: &Cell<T>) -> bool { |
| 291 | + self.get() < other.get() |
| 292 | + } |
| 293 | + |
| 294 | + #[inline] |
| 295 | + fn le(&self, other: &Cell<T>) -> bool { |
| 296 | + self.get() <= other.get() |
| 297 | + } |
| 298 | + |
| 299 | + #[inline] |
| 300 | + fn gt(&self, other: &Cell<T>) -> bool { |
| 301 | + self.get() > other.get() |
| 302 | + } |
| 303 | + |
| 304 | + #[inline] |
| 305 | + fn ge(&self, other: &Cell<T>) -> bool { |
| 306 | + self.get() >= other.get() |
| 307 | + } |
| 308 | +} |
| 309 | + |
| 310 | +#[stable(feature = "cell_ord", since = "1.10.0")] |
| 311 | +impl<T:Ord + Copy> Ord for Cell<T> { |
| 312 | + #[inline] |
| 313 | + fn cmp(&self, other: &Cell<T>) -> Ordering { |
| 314 | + self.get().cmp(&other.get()) |
| 315 | + } |
| 316 | +} |
| 317 | + |
282 | 318 | /// A mutable memory location with dynamically checked borrow rules
|
283 | 319 | ///
|
284 | 320 | /// See the [module-level documentation](index.html) for more.
|
@@ -514,6 +550,42 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
|
514 | 550 | #[stable(feature = "cell_eq", since = "1.2.0")]
|
515 | 551 | impl<T: ?Sized + Eq> Eq for RefCell<T> {}
|
516 | 552 |
|
| 553 | +#[stable(feature = "cell_ord", since = "1.10.0")] |
| 554 | +impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> { |
| 555 | + #[inline] |
| 556 | + fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> { |
| 557 | + self.borrow().partial_cmp(&*other.borrow()) |
| 558 | + } |
| 559 | + |
| 560 | + #[inline] |
| 561 | + fn lt(&self, other: &RefCell<T>) -> bool { |
| 562 | + *self.borrow() < *other.borrow() |
| 563 | + } |
| 564 | + |
| 565 | + #[inline] |
| 566 | + fn le(&self, other: &RefCell<T>) -> bool { |
| 567 | + *self.borrow() <= *other.borrow() |
| 568 | + } |
| 569 | + |
| 570 | + #[inline] |
| 571 | + fn gt(&self, other: &RefCell<T>) -> bool { |
| 572 | + *self.borrow() > *other.borrow() |
| 573 | + } |
| 574 | + |
| 575 | + #[inline] |
| 576 | + fn ge(&self, other: &RefCell<T>) -> bool { |
| 577 | + *self.borrow() >= *other.borrow() |
| 578 | + } |
| 579 | +} |
| 580 | + |
| 581 | +#[stable(feature = "cell_ord", since = "1.10.0")] |
| 582 | +impl<T: ?Sized + Ord> Ord for RefCell<T> { |
| 583 | + #[inline] |
| 584 | + fn cmp(&self, other: &RefCell<T>) -> Ordering { |
| 585 | + self.borrow().cmp(&*other.borrow()) |
| 586 | + } |
| 587 | +} |
| 588 | + |
517 | 589 | struct BorrowRef<'b> {
|
518 | 590 | borrow: &'b Cell<BorrowFlag>,
|
519 | 591 | }
|
|
0 commit comments