remove "get_with" method

This commit is contained in:
F001 2018-05-26 19:55:40 +08:00
parent 20b50f591f
commit 4bf8b57950
2 changed files with 2 additions and 26 deletions

View file

@ -510,8 +510,8 @@ impl<T: ?Sized> Cell<T> {
/// use std::cell::Cell;
/// let slice: &mut [i32] = &mut [1,2,3];
/// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
///
/// assert_eq!(cell_slice.get_with(|v|v.len()), 3)
/// let slice_cell : &[Cell<i32>] = &cell_slice[..];
/// assert_eq!(slice_cell.len(), 3)
/// ```
#[inline]
#[unstable(feature = "as_cell", issue="43038")]
@ -520,28 +520,6 @@ impl<T: ?Sized> Cell<T> {
&*(t as *mut T as *const Cell<T>)
}
}
/// Returns a value by applying a function on contained value
///
/// # Examples
///
/// ```
/// #![feature(as_cell)]
/// use std::cell::Cell;
/// let c : Cell<Vec<i32>> = Cell::new(vec![1,2,3]);
/// let sum : i32 = c.get_with(|v|v.iter().sum());
/// assert_eq!(sum, 6_i32);
/// ```
#[inline]
#[unstable(feature = "as_cell", issue="43038")]
pub fn get_with<U, F>(&self, f: F) -> U
where
F: Fn(&T) -> U, U: 'static
{
unsafe {
f(&*self.value.get())
}
}
}
impl<T: Default> Cell<T> {

View file

@ -15,8 +15,6 @@ use std::cell::Cell;
fn main() {
let slice: &mut [i32] = &mut [1,2,3];
let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
assert_eq!(cell_slice.get_with(|v|v.len()), 3);
let sub_slice : &[Cell<i32>] = &cell_slice[1..];
assert_eq!(sub_slice.len(), 2);
}