You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many times, there is a need for a simple dummy io::Reader + io::Writer, but currently the only options are io::Empty and io::Sink respectively. Having both of their functionality together requires writing your own boilerplate for something that makes sense to have in the standard library.
Motivation, use-cases
A simple idea for this is when a library requires a full stream, but as the developer, you don't really care about the output/input the library requires.
use std::io;structNeedsStream<S: io::Write + io::Read>{stream:T,}impl<S: io::Write + io::Read>NeedsStream<S>{fnnew(s:S) -> Self{unimplemented!()}// conducts some process, reading from the stream, and// sending some output to it on events.fnprocess(&mutself) -> bool{unimplemented!()}}// I just want the output `bool` of the processing, and // don't care about the stream processing.letmut n = io::null();let ns = NeedsStream::new(n);
ns.process();
Solution sketches
I recently had a use for this, but I had to create my own entire struct for such a simple use case:
io::Null
: a combination ofio::Sink
andio::Empty
Problem statement
Many times, there is a need for a simple dummy io::Reader + io::Writer, but currently the only options are io::Empty and io::Sink respectively. Having both of their functionality together requires writing your own boilerplate for something that makes sense to have in the standard library.
Motivation, use-cases
A simple idea for this is when a library requires a full stream, but as the developer, you don't really care about the output/input the library requires.
Solution sketches
I recently had a use for this, but I had to create my own entire struct for such a simple use case:
Links and related work
This idea was proposed in rust-lang/rust#24235 from a quick search.
This idea is also similiar to the
/dev/null
on Unix.The text was updated successfully, but these errors were encountered: