[−][src]Struct rustc_ap_rustc_data_structures::owning_ref::OwningRefMut
An mutable owning reference.
This wraps an owner O
and a reference &mut T
pointing
at something reachable from O::Target
while keeping
the ability to move self
around.
The owner is usually a pointer that points at some base type.
For more details and examples, see the module and method docs.
Methods
impl<O, T: ?Sized> OwningRefMut<O, T>
[src]
pub fn new(o: O) -> Self where
O: StableAddress,
O: DerefMut<Target = T>,
[src]
O: StableAddress,
O: DerefMut<Target = T>,
Creates a new owning reference from a owner initialized to the direct dereference of it.
Example
extern crate owning_ref; use owning_ref::OwningRefMut; fn main() { let owning_ref_mut = OwningRefMut::new(Box::new(42)); assert_eq!(*owning_ref_mut, 42); }
pub unsafe fn new_assert_stable_address(o: O) -> Self where
O: DerefMut<Target = T>,
[src]
O: DerefMut<Target = T>,
Like new
, but doesn’t require O
to implement the StableAddress
trait.
Instead, the caller is responsible to make the same promises as implementing the trait.
This is useful for cases where coherence rules prevents implementing the trait without adding a dependency to this crate in a third-party library.
pub fn map<F, U: ?Sized>(self, f: F) -> OwningRef<O, U> where
O: StableAddress,
F: FnOnce(&mut T) -> &U,
[src]
O: StableAddress,
F: FnOnce(&mut T) -> &U,
Converts self
into a new shared owning reference that points at
something reachable from the previous one.
This can be a reference to a field of U
, something reachable from a field of
U
, or even something unrelated with a 'static
lifetime.
Example
extern crate owning_ref; use owning_ref::OwningRefMut; fn main() { let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); // create a owning reference that points at the // third element of the array. let owning_ref = owning_ref_mut.map(|array| &array[2]); assert_eq!(*owning_ref, 3); }
pub fn map_mut<F, U: ?Sized>(self, f: F) -> OwningRefMut<O, U> where
O: StableAddress,
F: FnOnce(&mut T) -> &mut U,
[src]
O: StableAddress,
F: FnOnce(&mut T) -> &mut U,
Converts self
into a new mutable owning reference that points at
something reachable from the previous one.
This can be a reference to a field of U
, something reachable from a field of
U
, or even something unrelated with a 'static
lifetime.
Example
extern crate owning_ref; use owning_ref::OwningRefMut; fn main() { let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); // create a owning reference that points at the // third element of the array. let owning_ref_mut = owning_ref_mut.map_mut(|array| &mut array[2]); assert_eq!(*owning_ref_mut, 3); }
pub fn try_map<F, U: ?Sized, E>(self, f: F) -> Result<OwningRef<O, U>, E> where
O: StableAddress,
F: FnOnce(&mut T) -> Result<&U, E>,
[src]
O: StableAddress,
F: FnOnce(&mut T) -> Result<&U, E>,
Tries to convert self
into a new shared owning reference that points
at something reachable from the previous one.
This can be a reference to a field of U
, something reachable from a field of
U
, or even something unrelated with a 'static
lifetime.
Example
extern crate owning_ref; use owning_ref::OwningRefMut; fn main() { let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); // create a owning reference that points at the // third element of the array. let owning_ref = owning_ref_mut.try_map(|array| { if array[2] == 3 { Ok(&array[2]) } else { Err(()) } }); assert_eq!(*owning_ref.unwrap(), 3); }
pub fn try_map_mut<F, U: ?Sized, E>(self, f: F) -> Result<OwningRefMut<O, U>, E> where
O: StableAddress,
F: FnOnce(&mut T) -> Result<&mut U, E>,
[src]
O: StableAddress,
F: FnOnce(&mut T) -> Result<&mut U, E>,
Tries to convert self
into a new mutable owning reference that points
at something reachable from the previous one.
This can be a reference to a field of U
, something reachable from a field of
U
, or even something unrelated with a 'static
lifetime.
Example
extern crate owning_ref; use owning_ref::OwningRefMut; fn main() { let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); // create a owning reference that points at the // third element of the array. let owning_ref_mut = owning_ref_mut.try_map_mut(|array| { if array[2] == 3 { Ok(&mut array[2]) } else { Err(()) } }); assert_eq!(*owning_ref_mut.unwrap(), 3); }
pub unsafe fn map_owner<F, P>(self, f: F) -> OwningRefMut<P, T> where
O: StableAddress,
P: StableAddress,
F: FnOnce(O) -> P,
[src]
O: StableAddress,
P: StableAddress,
F: FnOnce(O) -> P,
Converts self
into a new owning reference with a different owner type.
The new owner type needs to still contain the original owner in some way so that the reference into it remains valid. This function is marked unsafe because the user needs to manually uphold this guarantee.
pub fn map_owner_box(self) -> OwningRefMut<Box<O>, T>
[src]
Converts self
into a new owning reference where the owner is wrapped
in an additional Box<O>
.
This can be used to safely erase the owner of any OwningRefMut<O, T>
to a OwningRefMut<Box<Erased>, T>
.
pub fn erase_owner<'a>(self) -> OwningRefMut<O::Erased, T> where
O: IntoErased<'a>,
[src]
O: IntoErased<'a>,
Erases the concrete base type of the owner with a trait object.
This allows mixing of owned references with different owner base types.
Example
extern crate owning_ref; use owning_ref::{OwningRefMut, Erased}; fn main() { // N.B., using the concrete types here for explicitness. // For less verbose code type aliases like `BoxRef` are provided. let owning_ref_mut_a: OwningRefMut<Box<[i32; 4]>, [i32; 4]> = OwningRefMut::new(Box::new([1, 2, 3, 4])); let owning_ref_mut_b: OwningRefMut<Box<Vec<(i32, bool)>>, Vec<(i32, bool)>> = OwningRefMut::new(Box::new(vec![(0, false), (1, true)])); let owning_ref_mut_a: OwningRefMut<Box<[i32; 4]>, i32> = owning_ref_mut_a.map_mut(|a| &mut a[0]); let owning_ref_mut_b: OwningRefMut<Box<Vec<(i32, bool)>>, i32> = owning_ref_mut_b.map_mut(|a| &mut a[1].0); let owning_refs_mut: [OwningRefMut<Box<Erased>, i32>; 2] = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()]; assert_eq!(*owning_refs_mut[0], 1); assert_eq!(*owning_refs_mut[1], 1); }
ⓘImportant traits for &'_ mut Ipub fn owner(&self) -> &O
[src]
A getter for the underlying owner.
pub fn into_inner(self) -> O
[src]
Discards the reference and retrieves the owner.
Trait Implementations
impl<O, T: ?Sized> AsMut<T> for OwningRefMut<O, T>
[src]
impl<O, T: ?Sized> AsRef<T> for OwningRefMut<O, T>
[src]
impl<O, T: ?Sized> Debug for OwningRefMut<O, T> where
O: Debug,
T: Debug,
[src]
O: Debug,
T: Debug,
impl<O, T: ?Sized> Deref for OwningRefMut<O, T>
[src]
type Target = T
The resulting type after dereferencing.
ⓘImportant traits for &'_ mut Ifn deref(&self) -> &T
[src]
impl<O, T: ?Sized> DerefMut for OwningRefMut<O, T>
[src]
impl<O, T: ?Sized> Eq for OwningRefMut<O, T> where
T: Eq,
[src]
T: Eq,
impl<O, T: ?Sized> From<O> for OwningRefMut<O, T> where
O: StableAddress,
O: DerefMut<Target = T>,
[src]
O: StableAddress,
O: DerefMut<Target = T>,
impl<O, T: ?Sized> From<OwningRefMut<O, T>> for OwningRef<O, T> where
O: StableAddress,
O: DerefMut<Target = T>,
[src]
O: StableAddress,
O: DerefMut<Target = T>,
fn from(other: OwningRefMut<O, T>) -> Self
[src]
impl<O, T: ?Sized> Hash for OwningRefMut<O, T> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<O, T: ?Sized> Ord for OwningRefMut<O, T> where
T: Ord,
[src]
T: Ord,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<O, T: ?Sized> PartialEq<OwningRefMut<O, T>> for OwningRefMut<O, T> where
T: PartialEq,
[src]
T: PartialEq,
impl<O, T: ?Sized> PartialOrd<OwningRefMut<O, T>> for OwningRefMut<O, T> where
T: PartialOrd,
[src]
T: PartialOrd,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<O, T: ?Sized> Send for OwningRefMut<O, T> where
O: Send,
&'a mut T: Send,
[src]
O: Send,
&'a mut T: Send,
impl<O, T: ?Sized> Sync for OwningRefMut<O, T> where
O: Sync,
&'a mut T: Sync,
[src]
O: Sync,
&'a mut T: Sync,
Auto Trait Implementations
impl<O, T: ?Sized> RefUnwindSafe for OwningRefMut<O, T> where
O: RefUnwindSafe,
T: RefUnwindSafe,
O: RefUnwindSafe,
T: RefUnwindSafe,
impl<O, T: ?Sized> Unpin for OwningRefMut<O, T> where
O: Unpin,
O: Unpin,
impl<O, T: ?Sized> UnwindSafe for OwningRefMut<O, T> where
O: UnwindSafe,
T: RefUnwindSafe,
O: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Ifn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> Erased for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<E> SpecializationError for E
[src]
default fn not_found<S, T>(
trait_name: &'static str,
method_name: &'static str
) -> E where
T: ?Sized,
[src]
trait_name: &'static str,
method_name: &'static str
) -> E where
T: ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,