Created
March 7, 2017 17:13
-
-
Save robey/7464dd437d20f8ea7315be775207b969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ByteStream = Stream<Item = EasyBuf, Error = io::Error>; | |
// pub fn framed_stream<T>(s: T) -> impl T | |
// where T: Stream<Item = EasyBuf, Error = io::Error> | |
// convert a byte stream into a stream with each chunk prefixed by a length | |
// marker, suitable for embedding in a bottle. | |
pub fn framed_stream<T>(s: T) -> stream::Flatten< | |
stream::Map<T, fn(EasyBuf) -> stream::IterStream<vec::IntoIter<Result<EasyBuf, io::Error>>>> | |
> | |
where T: Stream<Item = EasyBuf, Error = io::Error> | |
{ | |
fn frame(buffer: EasyBuf) -> stream::IterStream<vec::IntoIter<Result<EasyBuf, io::Error>>> { | |
stream::iter(vec![ Ok(EasyBuf::from(zint::encode_length(buffer.len() as u32))), Ok(buffer) ]) | |
} | |
let x = s.map(frame as fn(EasyBuf) -> stream::IterStream<vec::IntoIter<Result<EasyBuf, io::Error>>>); | |
x.flatten() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment