Move std::cell::clone_ref to a clone associated function on std::cell::Ref
... and generalize the bounds on the value type.
This commit is contained in:
parent
621a10e7f3
commit
c516eee503
2 changed files with 22 additions and 5 deletions
|
|
@ -545,13 +545,30 @@ impl<'b, T: ?Sized> Deref for Ref<'b, T> {
|
|||
///
|
||||
/// A `Clone` implementation would interfere with the widespread
|
||||
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
|
||||
#[deprecated(since = "1.2.0", reason = "moved to a `Ref::clone` associated function")]
|
||||
#[unstable(feature = "core",
|
||||
reason = "likely to be moved to a method, pending language changes")]
|
||||
#[inline]
|
||||
pub fn clone_ref<'b, T:Clone>(orig: &Ref<'b, T>) -> Ref<'b, T> {
|
||||
Ref {
|
||||
_value: orig._value,
|
||||
_borrow: orig._borrow.clone(),
|
||||
Ref::clone(orig)
|
||||
}
|
||||
|
||||
impl<'b, T: ?Sized> Ref<'b, T> {
|
||||
/// Copies a `Ref`.
|
||||
///
|
||||
/// The `RefCell` is already immutably borrowed, so this cannot fail.
|
||||
///
|
||||
/// This is an associated function that needs to be used as `Ref::clone(...)`.
|
||||
/// A `Clone` implementation or a method would interfere with the widespread
|
||||
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
|
||||
#[unstable(feature = "cell_extras",
|
||||
reason = "likely to be moved to a method, pending language changes")]
|
||||
#[inline]
|
||||
pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> {
|
||||
Ref {
|
||||
_value: orig._value,
|
||||
_borrow: orig._borrow.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,13 +115,13 @@ fn discard_doesnt_unborrow() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn clone_ref_updates_flag() {
|
||||
fn ref_clone_updates_flag() {
|
||||
let x = RefCell::new(0);
|
||||
{
|
||||
let b1 = x.borrow();
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
{
|
||||
let _b2 = clone_ref(&b1);
|
||||
let _b2 = Ref::clone(&b1);
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
}
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue