rust-lang/rust — pull request #19220 by tbu- (2014-11-22 22:10:06+00:00)
Title: Add `map` function to `Ref` and `MutRef` of `RefCell`

This enables one to return references to things inside the primary `RefCell`
content, like this code:

```
use std::cell::RefCell;
use std::cell::Ref;

struct ContainsVector {
vec: RefCell>,
}

impl ContainsVector {
fn new() -> ContainsVector {
ContainsVector { vec: RefCell::new(vec![0]) }
}
fn index<'a>(&'a self, i: uint) -> Ref<'a, &'a u32> {
self.vec.borrow().map(|v| &v[i])
}
fn index_mut<'a>(&'a self, i: uint) -> RefMut<'a, &'a mut u32> {
self.vec.borrow_mut().map(|v| &mut v[i])
}
}

fn main() {
let cv = ContainsVector::new();
**cv.index_mut(0) = 1;
cv.index(0);
}
```