Show impl for Ref & RefMut
This commit is contained in:
parent
907d961876
commit
a8f581fad1
@ -385,6 +385,7 @@ impl<'b, T> DerefMut<T> for RefMut<'b, T> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use mem::drop;
|
||||
|
||||
#[test]
|
||||
fn smoketest_cell() {
|
||||
@ -412,6 +413,22 @@ mod test {
|
||||
assert!(format!("{}", x).as_slice().contains(x.get()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ref_and_refmut_have_sensible_show() {
|
||||
use str::StrSlice;
|
||||
use realstd::str::Str;
|
||||
|
||||
let refcell = RefCell::new("foo");
|
||||
|
||||
let refcell_refmut = refcell.borrow_mut();
|
||||
assert!(format!("{}", refcell_refmut).as_slice().contains("foo"));
|
||||
drop(refcell_refmut);
|
||||
|
||||
let refcell_ref = refcell.borrow();
|
||||
assert!(format!("{}", refcell_ref).as_slice().contains("foo"));
|
||||
drop(refcell_ref);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_imm_borrow() {
|
||||
let x = RefCell::new(0);
|
||||
|
@ -13,13 +13,14 @@
|
||||
#![allow(unused_variable)]
|
||||
|
||||
use any;
|
||||
use cell::Cell;
|
||||
use cell::{Cell, Ref, RefMut};
|
||||
use char::Char;
|
||||
use collections::Collection;
|
||||
use iter::{Iterator, range};
|
||||
use kinds::Copy;
|
||||
use mem;
|
||||
use option::{Option, Some, None};
|
||||
use ops::Deref;
|
||||
use result::{Ok, Err};
|
||||
use result;
|
||||
use slice::{Vector, ImmutableVector};
|
||||
@ -849,5 +850,17 @@ impl<T: Copy + Show> Show for Cell<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for Ref<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
(**self).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for RefMut<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
(*(self.deref())).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
|
||||
// it's a lot easier than creating all of the rt::Piece structures here.
|
||||
|
Loading…
x
Reference in New Issue
Block a user