scoped-stream-sink
Convenience library to construct streams and sinks.
📌 Plan for 2.0
Since AFIT (and RPITIT) is stabilized, i plan to upgrade this library's interface to use them.
This should eliminate the Box::pin
requirement, at the cost of complicated type bounds
(and harder to use too, maybe).
So far i've been unsuccessful to fully reason the type bounds.
So here are the (rough) plan for (possible) 2.0:
- Eliminate
Box::pin
requirement (maybe add type alias for dynamic version). - Beef up
StreamSink
functionality (right now it's kinda experimental).
How to Use
Simply import this crate to your project and done. Documentation is already included, and it's very easy to use.
Examples
use Duration;
use Error;
use Sink;
use Stream;
use ;
use *;
async
Why?
Because implementing proper Stream
and Sink
is hard.
Originally i used it to make a network packet processor (think primitive services).
And since the code has potential, i decided to factor it out into dedicated crate.
Also, it's kinda hacky/cool way to make generators.
use pin;
use NonNull;
use ;
use Sink;
use Stream;
use ;
use *;
/// Create a null waker. It does nothing when waken.
How?
On it's basic, there's a inner pinned value that's mutably accessible
within and outside the sink/stream. Since that's kinda violates aliasing mutable borrow,
it's only permitted to be used within a single thread.
It should be fine however, since the borrow is done sequentially,
"passing" between inner and outer context.
To enforce this the local variants simply does not allow Send
,
while the non-local ones are using simple locks, which panics if locking failed.
In practice, care must be done to ensure the stream/sink can be awoken from inside and outside, while not using the waker itself. There should be no way for the stream/sink to not wait for something, unless if it's already finished/closed.
License
This library is licensed under Apache 2.0 license.