# [−][src]Struct owning_ref::OwningHandle

    pub struct OwningHandle<O, H> where
        O: StableAddress,
        H: Deref,  { /* fields omitted */ }

`OwningHandle` is a complement to `OwningRef`. Where `OwningRef` allows consumers to pass around an owned object and a dependent reference, `OwningHandle` contains an owned object and a dependent object.

`OwningHandle` can encapsulate a `RefMut` along with its associated `RefCell`, or an `RwLockReadGuard` along with its associated `RwLock`. However, the API is completely generic and there are no restrictions on what types of owning and dependent objects may be used.

`OwningHandle` is created by passing an owner object (which dereferences to a stable address) along with a callback which receives a pointer to that stable location. The callback may then dereference the pointer and mint a dependent object, with the guarantee that the returned object will not outlive the referent of the pointer.

Since the callback needs to dereference a raw pointer, it requires `unsafe` code. To avoid forcing this unsafety on most callers, the `ToHandle` trait is implemented for common data structures. Types that implement `ToHandle` can be wrapped into an `OwningHandle` without passing a callback.

## Methods

### `impl<O, H> OwningHandle<O, H> where
O: StableAddress,
O::Target: ToHandle<Handle = H>,
H: Deref,` [src]

#### `pub fn new(o: O) -> Self`[src]

Create a new `OwningHandle` for a type that implements `ToHandle`. For types that don't implement `ToHandle`, callers may invoke `new_with_fn`, which accepts a callback to perform the conversion.

### `impl<O, H> OwningHandle<O, H> where
O: StableAddress,
O::Target: ToHandleMut<HandleMut = H>,
H: DerefMut,` [src]

#### `pub fn new_mut(o: O) -> Self`[src]

Create a new mutable `OwningHandle` for a type that implements `ToHandleMut`.

### `impl<O, H> OwningHandle<O, H> where
O: StableAddress,
H: Deref,` [src]

#### `pub fn new_with_fn<F>(o: O, f: F) -> Self where
F: FnOnce(*const O::Target) -> H,` [src]

Create a new OwningHandle. The provided callback will be invoked with a pointer to the object owned by `o`, and the returned value is stored as the object to which this `OwningHandle` will forward `Deref` and `DerefMut`.

#### `pub fn try_new<F, E>(o: O, f: F) -> Result<Self, E> where
F: FnOnce(*const O::Target) -> Result<H, E>,` [src]

Create a new OwningHandle. The provided callback will be invoked with a pointer to the object owned by `o`, and the returned value is stored as the object to which this `OwningHandle` will forward `Deref` and `DerefMut`.

#### `pub fn as_owner(&self) -> &O`[src]

A getter for the underlying owner.

#### `pub fn into_owner(self) -> O`[src]

Discards the dependent object and returns the owner.

## Trait Implementations

### `impl<O, H> DerefMut for OwningHandle<O, H> where
O: StableAddress,
H: DerefMut,` [src]

#### `fn deref_mut(&mut self) -> &mut H::Target`[src]

Mutably dereferences the value.

### `impl<O, H> Deref for OwningHandle<O, H> where
O: StableAddress,
H: Deref,` [src]

#### `type Target = H::Target`

The resulting type after dereferencing.

#### `fn deref(&self) -> &H::Target`[src]

Dereferences the value.

### `impl<O, H> StableDeref for OwningHandle<O, H> where
O: StableAddress,
H: StableAddress,` [src]

## Auto Trait Implementations

### `impl<O, H> Send for OwningHandle<O, H> where
H: Send,
O: Send,`

### `impl<O, H> Unpin for OwningHandle<O, H> where
H: Unpin,
O: Unpin,`

### `impl<O, H> Sync for OwningHandle<O, H> where
H: Sync,
O: Sync,`

### `impl<O, H> UnwindSafe for OwningHandle<O, H> where
H: UnwindSafe,
O: UnwindSafe,`

### `impl<O, H> RefUnwindSafe for OwningHandle<O, H> where
H: RefUnwindSafe,
O: RefUnwindSafe,`

## Blanket Implementations

### `impl<T> Erased for T`[src]

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `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]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)