|
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};
|
@@ -267,6 +267,42 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
|
267 | 267 | #[stable(feature = "cell_eq", since = "1.2.0")]
|
268 | 268 | impl<T:Eq + Copy> Eq for Cell<T> {}
|
269 | 269 |
|
| 270 | +#[unstable(feature = "cell_ord", issue = "33305")] |
| 271 | +impl<T:PartialOrd + Copy> PartialOrd for Cell<T> { |
| 272 | + #[inline] |
| 273 | + fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> { |
| 274 | + self.get().partial_cmp(&other.get()) |
| 275 | + } |
| 276 | + |
| 277 | + #[inline] |
| 278 | + fn lt(&self, other: &Cell<T>) -> bool { |
| 279 | + self.get() < other.get() |
| 280 | + } |
| 281 | + |
| 282 | + #[inline] |
| 283 | + fn le(&self, other: &Cell<T>) -> bool { |
| 284 | + self.get() <= other.get() |
| 285 | + } |
| 286 | + |
| 287 | + #[inline] |
| 288 | + fn gt(&self, other: &Cell<T>) -> bool { |
| 289 | + self.get() > other.get() |
| 290 | + } |
| 291 | + |
| 292 | + #[inline] |
| 293 | + fn ge(&self, other: &Cell<T>) -> bool { |
| 294 | + self.get() >= other.get() |
| 295 | + } |
| 296 | +} |
| 297 | + |
| 298 | +#[unstable(feature = "cell_ord", issue = "33305")] |
| 299 | +impl<T:Ord + Copy> Ord for Cell<T> { |
| 300 | + #[inline] |
| 301 | + fn cmp(&self, other: &Cell<T>) -> Ordering { |
| 302 | + self.get().cmp(&other.get()) |
| 303 | + } |
| 304 | +} |
| 305 | + |
270 | 306 | /// A mutable memory location with dynamically checked borrow rules
|
271 | 307 | ///
|
272 | 308 | /// See the [module-level documentation](index.html) for more.
|
@@ -490,6 +526,42 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
|
490 | 526 | #[stable(feature = "cell_eq", since = "1.2.0")]
|
491 | 527 | impl<T: ?Sized + Eq> Eq for RefCell<T> {}
|
492 | 528 |
|
| 529 | +#[unstable(feature = "cell_ord", issue = "33305")] |
| 530 | +impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> { |
| 531 | + #[inline] |
| 532 | + fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> { |
| 533 | + self.borrow().partial_cmp(&*other.borrow()) |
| 534 | + } |
| 535 | + |
| 536 | + #[inline] |
| 537 | + fn lt(&self, other: &RefCell<T>) -> bool { |
| 538 | + *self.borrow() < *other.borrow() |
| 539 | + } |
| 540 | + |
| 541 | + #[inline] |
| 542 | + fn le(&self, other: &RefCell<T>) -> bool { |
| 543 | + *self.borrow() <= *other.borrow() |
| 544 | + } |
| 545 | + |
| 546 | + #[inline] |
| 547 | + fn gt(&self, other: &RefCell<T>) -> bool { |
| 548 | + *self.borrow() > *other.borrow() |
| 549 | + } |
| 550 | + |
| 551 | + #[inline] |
| 552 | + fn ge(&self, other: &RefCell<T>) -> bool { |
| 553 | + *self.borrow() >= *other.borrow() |
| 554 | + } |
| 555 | +} |
| 556 | + |
| 557 | +#[unstable(feature = "cell_ord", issue = "33305")] |
| 558 | +impl<T: ?Sized + Ord> Ord for RefCell<T> { |
| 559 | + #[inline] |
| 560 | + fn cmp(&self, other: &RefCell<T>) -> Ordering { |
| 561 | + self.borrow().cmp(&*other.borrow()) |
| 562 | + } |
| 563 | +} |
| 564 | + |
493 | 565 | struct BorrowRef<'b> {
|
494 | 566 | borrow: &'b Cell<BorrowFlag>,
|
495 | 567 | }
|
|
0 commit comments