AssertUnmoved

Struct AssertUnmoved 

Source
pub struct AssertUnmoved<T> { /* private fields */ }
Expand description

A type that asserts that the underlying type is not moved after being pinned and mutably accessed.

See crate level documentation for details.

Implementations§

Source§

impl<T> AssertUnmoved<T>

Source

pub const fn new(inner: T) -> Self

Creates a new AssertUnmoved.

Source

pub const fn get_ref(&self) -> &T

Gets a reference to the underlying type.

Unlike get_mut method, this method can always called.

You can also access the underlying type via Deref impl.

Source

pub fn get_mut(&mut self) -> &mut T

Gets a mutable reference to the underlying type.

Note that this method can only be called before pinned since AssertUnmoved is !Unpin (this is guaranteed by the type system!).

§Panics

Panics if this AssertUnmoved moved after being pinned and mutably accessed.

Source

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

Gets a pinned mutable reference to the underlying type.

§Panics

Panics if this AssertUnmoved moved after being pinned and mutably accessed.

§Examples

Implement own Stream trait for AssertUnmoved.

use std::{
    pin::Pin,
    task::{Context, Poll},
};

use assert_unmoved::AssertUnmoved;

pub trait MyStream {
    type Item;

    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
}

impl<S: MyStream> MyStream for AssertUnmoved<S> {
    type Item = S::Item;

    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
        self.get_pin_mut().poll_next(cx)
    }
}

Trait Implementations§

Source§

impl<R: AsyncBufRead> AsyncBufRead for AssertUnmoved<R>

Available on crate feature futures03 only.
Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amt: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncBufRead> AsyncBufRead for AssertUnmoved<R>

Available on crate feature tokio02 only.
Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amt: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncBufRead> AsyncBufRead for AssertUnmoved<R>

Available on crate feature tokio03 only.
Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amt: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncBufRead> AsyncBufRead for AssertUnmoved<R>

Available on crate feature tokio1 only.
Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amt: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncRead> AsyncRead for AssertUnmoved<R>

Available on crate feature futures03 only.
Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<R: AsyncRead> AsyncRead for AssertUnmoved<R>

Available on crate feature tokio02 only.
Source§

unsafe fn prepare_uninitialized_buffer( &self, buf: &mut [MaybeUninit<u8>], ) -> bool

Prepares an uninitialized buffer to be safe to pass to read. Returns true if the supplied buffer was zeroed out. Read more
Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>

Attempts to read from the AsyncRead into buf. Read more
Source§

fn poll_read_buf<B: BufMut>( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B, ) -> Poll<Result<usize>>
where Self: Sized,

Pulls some bytes from this source into the specified BufMut, returning how many bytes were read. Read more
Source§

impl<R: AsyncRead> AsyncRead for AssertUnmoved<R>

Available on crate feature tokio03 only.
Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<()>>

Attempts to read from the AsyncRead into buf. Read more
Source§

impl<R: AsyncRead> AsyncRead for AssertUnmoved<R>

Available on crate feature tokio1 only.
Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<()>>

Attempts to read from the AsyncRead into buf. Read more
Source§

impl<S: AsyncSeek> AsyncSeek for AssertUnmoved<S>

Available on crate feature futures03 only.
Source§

fn poll_seek( self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom, ) -> Poll<Result<u64>>

Attempt to seek to an offset, in bytes, in a stream. Read more
Source§

impl<S: AsyncSeek> AsyncSeek for AssertUnmoved<S>

Available on crate feature tokio02 only.
Source§

fn start_seek( self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom, ) -> Poll<Result<()>>

Attempts to seek to an offset, in bytes, in a stream. Read more
Source§

fn poll_complete( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<u64>>

Waits for a seek operation to complete. Read more
Source§

impl<S: AsyncSeek> AsyncSeek for AssertUnmoved<S>

Available on crate feature tokio03 only.
Source§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

Attempts to seek to an offset, in bytes, in a stream. Read more
Source§

fn poll_complete( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<u64>>

Waits for a seek operation to complete. Read more
Source§

impl<S: AsyncSeek> AsyncSeek for AssertUnmoved<S>

Available on crate feature tokio1 only.
Source§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

Attempts to seek to an offset, in bytes, in a stream. Read more
Source§

fn poll_complete( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<u64>>

Waits for a seek operation to complete. Read more
Source§

impl<W: AsyncWrite> AsyncWrite for AssertUnmoved<W>

Available on crate feature futures03 only.
Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

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

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Attempt to close the object. Read more
Source§

impl<W: AsyncWrite> AsyncWrite for AssertUnmoved<W>

Available on crate feature tokio02 only.
Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

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

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Source§

fn poll_write_buf<B: Buf>( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B, ) -> Poll<Result<usize, Error>>
where Self: Sized,

Writes a Buf into this value, returning how many bytes were written. Read more
Source§

impl<W: AsyncWrite> AsyncWrite for AssertUnmoved<W>

Available on crate feature tokio03 only.
Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

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

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Like poll_write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

Determines if this writer has an efficient poll_write_vectored implementation. Read more
Source§

impl<W: AsyncWrite> AsyncWrite for AssertUnmoved<W>

Available on crate feature tokio1 only.
Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

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

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Like poll_write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

Determines if this writer has an efficient poll_write_vectored implementation. Read more
Source§

impl<T: Debug> Debug for AssertUnmoved<T>

Source§

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

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

impl<T: Default> Default for AssertUnmoved<T>

Source§

fn default() -> Self

Creates a new AssertUnmoved, with the default value for T.

This is equivalent to AssertUnmoved::new(T::default()).

Source§

impl<T> Deref for AssertUnmoved<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> Drop for AssertUnmoved<T>

Source§

fn drop(&mut self)

§Panics

Panics if this AssertUnmoved moved after being pinned and mutably accessed.

Source§

impl<T> From<T> for AssertUnmoved<T>

Source§

fn from(inner: T) -> Self

Converts a T into a AssertUnmoved<T>.

This is equivalent to AssertUnmoved::new.

Source§

impl<F: FusedFuture> FusedFuture for AssertUnmoved<F>

Available on crate feature futures03 only.
Source§

fn is_terminated(&self) -> bool

Returns true if the underlying future should no longer be polled.
Source§

impl<S: FusedStream> FusedStream for AssertUnmoved<S>

Available on crate feature futures03 only.
Source§

fn is_terminated(&self) -> bool

Returns true if the stream should no longer be polled.
Source§

impl<F: Future> Future for AssertUnmoved<F>

Source§

type Output = <F 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<S: Sink<Item>, Item> Sink<Item> for AssertUnmoved<S>

Available on crate feature futures03 only.
Source§

type Error = <S as Sink<Item>>::Error

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
Source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl<S: Stream> Stream for AssertUnmoved<S>

Available on crate feature futures03 only.
Source§

type Item = <S as Stream>::Item

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AssertUnmoved<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AssertUnmoved<T>
where T: RefUnwindSafe,

§

impl<T> Send for AssertUnmoved<T>
where T: Send,

§

impl<T> Sync for AssertUnmoved<T>
where T: Sync,

§

impl<T> UnwindSafe for AssertUnmoved<T>
where T: UnwindSafe,

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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<F, T, E> TryFuture for F
where F: Future<Output = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll( self: Pin<&mut F>, cx: &mut Context<'_>, ) -> Poll<<F as Future>::Output>

Poll this TryFuture as if it were a Future. Read more
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.
Source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more