Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward Show, Eq, and Hash to RefCell's contents #16714

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libcollections/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ use core::prelude::*;

use alloc::boxed::Box;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::intrinsics::TypeId;
use core::mem;

Expand Down Expand Up @@ -239,6 +240,13 @@ impl<S: Writer, T: Hash<S>> Hash<S> for Rc<T> {
}
}

impl<S: Writer, T: Hash<S>> Hash<S> for RefCell<T> {
#[inline]
fn hash(&self, state: &mut S) {
self.borrow().hash(state);
}
}

impl<S: Writer, T: Hash<S>> Hash<S> for Option<T> {
#[inline]
fn hash(&self, state: &mut S) {
Expand Down
13 changes: 12 additions & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@
// FIXME: Relationship to Atomic types and RWLock

use clone::Clone;
use cmp::PartialEq;
use cmp::{PartialEq, Eq};
use kinds::{marker, Copy};
use ops::{Deref, DerefMut, Drop};
use option::{None, Option, Some};
use std::fmt;

/// A mutable memory location that admits only `Copy` data.
#[unstable = "likely to be renamed; otherwise stable"]
Expand Down Expand Up @@ -322,6 +323,16 @@ impl<T: PartialEq> PartialEq for RefCell<T> {
}
}

#[unstable = "waiting for `Eq` to become stable"]
impl<T: Eq> Eq for RefCell<T> {}

#[unstable = "waiting for `Show` to become stable"]
impl<T: fmt::Show> fmt::Show for RefCell<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.borrow().fmt(f)
}
}

/// Wraps a borrowed reference to a value in a `RefCell` box.
#[unstable]
pub struct Ref<'b, T> {
Expand Down