use selfie::refs::{Mut, Ref}; use selfie::{Selfie, SelfieMut}; use std::cell::Cell; use std::pin::Pin; // From https://github.com/Kimundi/owning-ref-rs/issues/49 fn helper(owning_ref: Selfie>, Ref>>) -> u8 { owning_ref.owned().set(10); owning_ref.with_referential(|r| r.set(20)); owning_ref.owned().get() } #[test] fn cell() { let val = Box::pin(Cell::new(25)); let owning_ref = Selfie::new(val, |c| c); let res = helper(owning_ref); assert_eq!(res, 20); } fn helper_mut(owning_ref: SelfieMut>, Mut>>) -> u8 { owning_ref.with_referential(|r| r.set(20)); owning_ref.with_referential(|r| r.get()) } #[test] fn cell_mut() { let val = Box::pin(Cell::new(25)); let owning_ref = SelfieMut::new(val, |c| Pin::get_mut(c)); let res = helper_mut(owning_ref); assert_eq!(res, 20); }