Struct Buffered

Source
pub struct Buffered<'a, T: ?Sized>(/* private fields */);
Expand description

A pointer to objects stored in buffers.

Containers such as &mut [u8] or &mut Vec<u8> yield this pointer type. Note that, unlike most pointer types, it implements Unpin only if T is Unpin. While this may seem counterintuitive, it simplifies obtaining a pinned reference to T in safe Rust, as illustrated below:

fn async_hello() -> Fn!(=> dyn Future<Output = String>) {
    from_fn!(|| async { String::from("Hello!") })
}

let mut stack = MaybeUninit::<[u8; 16]>::uninit();
let fut: Buffered<dyn Future<Output = String>> = async_hello().init(&mut stack);
// Pin it on the stack just as it has the inner type `T = dyn Future`.
let fut: Pin<&mut Buffered<_>> = std::pin::pin!(fut);
// Then project it to obtain a pinned reference to `T`.
let fut: Pin<&mut dyn Future<Output = String>> = fut.project();
assert_eq!(fut.await, "Hello!");

Tips: Buffered<T: Future> implements Future, so you can simply write async_hello().init(&mut stack).await in practice.

Implementations§

Source§

impl<'a, T: ?Sized> Buffered<'a, T>

Source

pub unsafe fn from_raw(ptr: NonNull<T>) -> Self

Constructs a new instance with the provided pointer.

§Safety

ptr must be a valid pointer to T and exclusive for the returned instance.

Source

pub fn into_raw(self) -> NonNull<T>

Consumes this instance, returning a raw pointer.

Source

pub fn project(self: Pin<&mut Self>) -> Pin<&mut T>

Returns a pinned mutable reference to the inner value.

Source

pub fn project_ref(self: Pin<&Self>) -> Pin<&T>

Returns a pinned immutable reference to the inner value.

Trait Implementations§

Source§

impl<T: ?Sized + Debug> Debug for Buffered<'_, T>

Source§

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

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

impl<T: ?Sized> Deref for Buffered<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for Buffered<'_, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized> Drop for Buffered<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Future for Buffered<'_, T>
where T: ?Sized + Future,

Source§

type Output = <T as Future>::Output

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

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

impl<T: ?Sized + Unpin> Unpin for Buffered<'_, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for Buffered<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for Buffered<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> !Send for Buffered<'a, T>

§

impl<'a, T> !Sync for Buffered<'a, T>

§

impl<'a, T> !UnwindSafe for Buffered<'a, T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.