Skip to content

Instantly share code, notes, and snippets.

@daschl
Created September 7, 2017 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daschl/42ea9da798192bb2eda8c2b0dfdf9005 to your computer and use it in GitHub Desktop.
Save daschl/42ea9da798192bb2eda8c2b0dfdf9005 to your computer and use it in GitHub Desktop.
use futures::sink::Sink;
use bytes::{Buf, Bytes, IntoBuf};
// I want to have SinkItem = IntoBuf so it accepts anything that I can turn into a Buf
trait Backend: Sink<SinkItem = Bytes, SinkError = u8> {}
impl<W: Write> Backend for WriterBackend<W> {}
impl<W: Write> Sink for WriterBackend<W> {
type SinkItem = Bytes; // <--- how would I change the associated type to accept IntoBuf ?
type SinkError = u8;
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
// use it! item.into_buf().bytes()
}
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
// omitted...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment