[][src]Trait owned::Take

pub unsafe trait Take<T: ?Sized>: Sized {
    fn take_unsized<F, R>(self, f: F) -> R
    where
        F: FnOnce(&mut ManuallyDrop<T>) -> R
; fn take_sized(self) -> T
    where
        T: Sized
, { ... }
fn take_owned(self) -> T::Owned
    where
        T: IntoOwned
, { ... } }

A trait for taking data.

Implementing Take<T> is like implementing Borrow<T> but for transferring ownership.

Safety

This trait is unsafe to implement because take_unsized() must not drop() or otherwise use the taken value after the closure returns.

Required methods

fn take_unsized<F, R>(self, f: F) -> R where
    F: FnOnce(&mut ManuallyDrop<T>) -> R, 

Takes ownership of an unsized type with the aid of a closure.

The closure is called with an mutable reference to ManuallyDrop<T>. After the closure returns the memory occupied by the value will be deallocated, but drop() will not be called on the value itself.

take_sized() and take_owned() are implemented in terms of this.

Loading content...

Provided methods

fn take_sized(self) -> T where
    T: Sized

Takes ownership of Sized type.

fn take_owned(self) -> T::Owned where
    T: IntoOwned

Takes ownership of the owned version of an unsized type.

Loading content...

Implementations on Foreign Types

impl<T> Take<T> for ManuallyDrop<T>[src]

impl<T: ?Sized + IntoOwned> Take<T> for Box<T>[src]

impl<T> Take<[T]> for Vec<T>[src]

Loading content...

Implementors

impl<T> Take<T> for T[src]

Loading content...