std::pin::PinBox - Rust
Description: API documentation for the Rust `PinBox` struct in crate `std`.
Keywords: rust, rustlang, rust-lang, PinBox

# [−][src]Struct std::pin::PinBox

    #[repr(transparent)]
    pub struct PinBox<T> where
        T: ?Sized,  { /* fields omitted */ }

🔬 This is a nightly-only experimental API. (`pin` #49150)

A pinned, heap allocated reference.

This type is similar to `Box`, except that it pins its value, which prevents it from moving out of the reference, unless it implements `Unpin`.

See the module documentation for furthur explaination on pinning.

## Methods

###

`impl<T> PinBox<T>`

[src]

####

`pub fn new(data: T) -> PinBox<T>`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Allocate memory on the heap, move the data into it and pin it.

###

`impl<T> PinBox<T> where T: ?Sized,`

[src]

####

`pub fn as_pin_mut(&'a mut self) -> PinMut<'a, T>`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Get a pinned reference to the data in this PinBox.

####

`pub unsafe fn from_raw(raw: *mut T) -> PinBox<T>`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Constructs a `PinBox` from a raw pointer.

After calling this function, the raw pointer is owned by the resulting `PinBox`. Specifically, the `PinBox` destructor will call the destructor of `T` and free the allocated memory. Since the way `PinBox` allocates and releases memory is unspecified, the only valid pointer to pass to this function is the one taken from another `PinBox` via the `PinBox::into_raw` function.

This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.

# Examples

    #![feature(pin)]
    use std::pin::PinBox;
    let x = PinBox::new(5);
    let ptr = PinBox::into_raw(x);
    let x = unsafe { PinBox::from_raw(ptr) };Run

####

`pub fn into_raw(b: PinBox<T>) -> *mut T`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Consumes the `PinBox`, returning the wrapped raw pointer.

After calling this function, the caller is responsible for the memory previously managed by the `PinBox`. In particular, the caller should properly destroy `T` and release the memory. The proper way to do so is to convert the raw pointer back into a `PinBox` with the `PinBox::from_raw` function.

Note: this is an associated function, which means that you have to call it as `PinBox::into_raw(b)` instead of `b.into_raw()`. This is so that there is no conflict with a method on the inner type.

# Examples

    #![feature(pin)]
    use std::pin::PinBox;
    let x = PinBox::new(5);
    let ptr = PinBox::into_raw(x);Run

####
ⓘImportant traits for &'a mut I

### Important traits for &'a mut I

`impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`

`pub unsafe fn get_mut(this: &'a mut PinBox<T>) -> &'a mut T`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Get a mutable reference to the data inside this PinBox.

This function is unsafe. Users must guarantee that the data is never moved out of this reference.

####
ⓘImportant traits for Box<I>

### Important traits for Box<I>

`impl<I> Iterator for Box<I> where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>`

`pub unsafe fn unpin(this: PinBox<T>) -> Box<T>`

[src]

🔬 This is a nightly-only experimental API. (`pin` #49150)

Convert this PinBox into an unpinned Box.

This function is unsafe. Users must guarantee that the data is never moved out of the box.

## Trait Implementations

###

`impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F> where F: Future<Output = T> + 'a,`

[src]

####

`fn into_raw(self) -> *mut ()`

[src]

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

Convert an owned instance into a (conceptually owned) void pointer.

####

`unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T>`

[src]

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

Poll the future represented by the given void pointer. Read more

####

`unsafe fn drop(ptr: *mut ())`

[src]

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

Drops the future represented by the given void pointer. Read more

###

`impl<T> Deref for PinBox<T> where T: ?Sized,`

[src]

#### `type Target = T`

The resulting type after dereferencing.

####
ⓘImportant traits for &'a mut I

### Important traits for &'a mut I

`impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`

`fn deref(&self) -> &T`

[src]

Dereferences the value.

###

`impl<T> DerefMut for PinBox<T> where T: Unpin + ?Sized,`

[src]

####
ⓘImportant traits for &'a mut I

### Important traits for &'a mut I

`impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`

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

[src]

Mutably dereferences the value.

###

`impl<T> Unpin for PinBox<T> where T: ?Sized,`

[src]

###

`impl<T> Display for PinBox<T> where T: Display + ?Sized,`

[src]

####

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

[src]

Formats the value using the given formatter. Read more

###

`impl<T> From<Box<T>> for PinBox<T> where T: ?Sized,`

[src]

####

`fn from(boxed: Box<T>) -> PinBox<T>`

[src]

Performs the conversion.

###

`impl<'a, F> From<PinBox<F>> for FutureObj<'a, ()> where F: 'a + Send + Future<Output = ()>,`

[src]

####

`fn from(boxed: PinBox<F>) -> FutureObj<'a, ()>`

[src]

Performs the conversion.

###

`impl<'a, F> From<PinBox<F>> for LocalFutureObj<'a, ()> where F: 'a + Future<Output = ()>,`

[src]

####

`fn from(boxed: PinBox<F>) -> LocalFutureObj<'a, ()>`

[src]

Performs the conversion.

###

`impl<T> From<PinBox<T>> for Box<T> where T: Unpin + ?Sized,`

[src]

####
ⓘImportant traits for Box<I>

### Important traits for Box<I>

`impl<I> Iterator for Box<I> where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>`

`fn from(pinned: PinBox<T>) -> Box<T>`

[src]

Performs the conversion.

###

`impl<F> Future for PinBox<F> where F: Future + ?Sized,`

[src]

#### `type Output = <F as Future>::Output`

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

The result of the `Future`.

####

`fn poll( self: PinMut<PinBox<F>>, cx: &mut Context ) -> Poll<<PinBox<F> as Future>::Output>`

[src]

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

###

`impl<T> Debug for PinBox<T> where T: Debug + ?Sized,`

[src]

####

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

[src]

Formats the value using the given formatter. Read more

###

`impl<T, U> CoerceUnsized<PinBox<U>> for PinBox<T> where T: Unsize<U> + ?Sized, U: ?Sized,`

[src]

###

`impl<T> Pointer for PinBox<T> where T: ?Sized,`

[src]

####

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

[src]

Formats the value using the given formatter.

## Auto Trait Implementations

###

`impl<T: ?Sized> Send for PinBox<T> where T: Send,`

###

`impl<T: ?Sized> Sync for PinBox<T> where T: Sync,`

## Blanket Implementations

###

`impl<T, U> TryFrom for T where T: From<U>,`

[src]

#### `type Error = !`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

####

`fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`

[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

###

`impl<T> From for T`

[src]

####

`fn from(t: T) -> T`

[src]

Performs the conversion.

###

`impl<T, U> TryInto for T where U: TryFrom<T>,`

[src]

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

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

####

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

[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

###

`impl<T, U> Into for T where U: From<T>,`

[src]

####

`fn into(self) -> U`

[src]

Performs the conversion.

###

`impl<T> Borrow for T where T: ?Sized,`

[src]

####
ⓘImportant traits for &'a mut I

### Important traits for &'a mut I

`impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`

`fn borrow(&self) -> &T`

[src]

Immutably borrows from an owned value. Read more

###

`impl<T> BorrowMut for T where T: ?Sized,`

[src]

####
ⓘImportant traits for &'a mut I

### Important traits for &'a mut I

`impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`

`fn borrow_mut(&mut self) -> &mut T`

[src]

Mutably borrows from an owned value. Read more

###

`impl<T> Any for T where T: 'static + ?Sized,`

[src]

####

`fn get_type_id(&self) -> TypeId`

[src]

🔬 This is a nightly-only experimental API. (`get_type_id` #27745)

this method will likely be replaced by an associated static

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

###

`impl<T> ToString for T where T: Display + ?Sized,`

[src]

####

`fn to_string(&self) -> String`

[src]

Converts the given value to a `String`. 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`)