pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRefMut<RwLockWriteGuard<'a, T>, U>;
Expand description

Typedef of a mutable owning reference that uses a RwLockWriteGuard as the owner.

Aliased Type§

struct RwLockWriteGuardRefMut<'a, T, U = T> {
    pub(crate) owner: RwLockWriteGuard<'a, T>,
    pub(crate) reference: *mut U,
}

Fields§

§owner: RwLockWriteGuard<'a, T>§reference: *mut U

Implementations§

source§

impl<O, T: ?Sized> OwningRefMut<O, T>

source

pub fn new(o: O) -> Selfwhere O: StableAddress + 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);
}
source

pub unsafe fn new_assert_stable_address(o: O) -> Selfwhere 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.

source

pub fn map<F, U: ?Sized>(self, f: F) -> OwningRef<O, U>where 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);
}
source

pub fn map_mut<F, U: ?Sized>(self, f: F) -> OwningRefMut<O, U>where 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);
}
source

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>,

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);
}
source

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>,

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);
}
source

pub unsafe fn map_owner<F, P>(self, f: F) -> OwningRefMut<P, T>where 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.

source

pub fn map_owner_box(self) -> OwningRefMut<Box<O>, T>

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<dyn Erased>, T>.

source

pub fn erase_owner<'a>(self) -> OwningRefMut<O::Erased, T>where 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() {
    // NB: Using the concrete types here for explicitnes.
    // 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<dyn 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);
}
source

pub fn as_owner(&self) -> &O

A reference to the underlying owner.

source

pub fn as_owner_mut(&mut self) -> &mut O

A mutable reference to the underlying owner.

source

pub fn into_owner(self) -> O

Discards the reference and retrieves the owner.

Trait Implementations§

source§

impl<O, T: ?Sized> AsMut<T> for OwningRefMut<O, T>

source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<O, T: ?Sized> AsRef<T> for OwningRefMut<O, T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<O, T> Debug for OwningRefMut<O, T>where O: Debug, T: Debug + ?Sized,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<O, T: ?Sized> Deref for OwningRefMut<O, T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<O, T: ?Sized> DerefMut for OwningRefMut<O, T>

source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
source§

impl<O, T: ?Sized> From<O> for OwningRefMut<O, T>where O: StableAddress + DerefMut<Target = T>,

source§

fn from(owner: O) -> Self

Converts to this type from the input type.
source§

impl<O, T> Hash for OwningRefMut<O, T>where T: Hash + ?Sized,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<O, T> Ord for OwningRefMut<O, T>where T: Ord + ?Sized,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<O, T> PartialEq<OwningRefMut<O, T>> for OwningRefMut<O, T>where T: PartialEq + ?Sized,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<O, T> PartialOrd<OwningRefMut<O, T>> for OwningRefMut<O, T>where T: PartialOrd + ?Sized,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<O, T> Eq for OwningRefMut<O, T>where T: Eq + ?Sized,

source§

impl<O, T: ?Sized> Send for OwningRefMut<O, T>where O: Send, for<'a> &'a mut T: Send,

source§

impl<O, T: ?Sized> StableDeref for OwningRefMut<O, T>

source§

impl<O, T: ?Sized> Sync for OwningRefMut<O, T>where O: Sync, for<'a> &'a mut T: Sync,