Struct pawawwewism::reader::Reader

source ·
pub struct Reader<R: Shutdown, O> { /* private fields */ }
Expand description

An owned thread that reads from a stream.

This type works with streams that can be shut down from another thread (via the Shutdown trait). That way, the worker thread can perform a blocking read on the stream, while the owning thread can still make the worker thread exit by shutting down the stream.

When a Reader is dropped, or Reader::stop is called, the stream will be shut down and the thread will be joined. If the thread has panicked, the panic will be propagated to the owner.

Implementations§

source§

impl<R: Shutdown, O> Reader<R, O>

source

pub fn spawn<F>(read: R, handler: F) -> Result<Reader<R, O>>where F: FnOnce(ReadWrapper<&R>) -> Result<O> + Send + 'static, R: Shutdown + Send + Sync + 'static, O: Send + 'static,

Spawns a Reader that will run handler in a separate thread.

The contract handler has to uphold is as follows: no blocking I/O must be performed, except for reading from the ReadWrapper passed to it.

Also see ReaderBuilder.

source

pub fn stop(self) -> Result<O>

Stops the Reader by shutting down the stream it is reading from.

After shutting down the stream, the thread will be joined and its return value will be returned.

If the thread has panicked, the panic will be propagated to the caller.

source

pub fn is_finished(&self) -> bool

Checks whether the Reader thread has finished execution.

Readers are allowed to return a value from their main function if they choose to exit. To access that value, call Reader::stop. They can also “finish” by panicking. Panics are propagated to the owner.

Trait Implementations§

source§

impl<R: Shutdown, O> Drop for Reader<R, O>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<R, O> !RefUnwindSafe for Reader<R, O>

§

impl<R, O> Send for Reader<R, O>where R: Send + Sync,

§

impl<R, O> Sync for Reader<R, O>where R: Send + Sync,

§

impl<R, O> Unpin for Reader<R, O>

§

impl<R, O> !UnwindSafe for Reader<R, O>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.