Required methods
(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
)
| 693 | { |
| 694 | // Required methods |
| 695 | fn poll_write( |
| 696 | mut self: Pin<&mut Self>, |
| 697 | cx: &mut Context<'_>, |
| 698 | buf: &[u8], |
| 699 | ) -> Poll<std::io::Result<usize>> { |
| 700 | let mut this = self.as_mut().project(); |
| 701 | |
| 702 | // Any leftover "needs" from previous loop? |
| 703 | match *this.sink_b_state { |
| 704 | SinkState::Needs(amt) => { |
| 705 | let res_b = if buf.len() > amt { |
| 706 | this.sink_b.poll_write(cx, &buf[..amt]) |
| 707 | } else { |
| 708 | this.sink_b.poll_write(cx, buf) |
| 709 | }; |
| 710 | |
| 711 | let res_b = match res_b { |
| 712 | Poll::Ready(Ok(wrote_b)) if wrote_b == amt => { |
| 713 | *this.sink_b_state = SinkState::Ready; |
| 714 | Poll::Ready(Ok(wrote_b)) |
| 715 | } |
| 716 | Poll::Ready(Ok(wrote_b)) => { |
| 717 | assert!(amt > wrote_b); |
| 718 | *this.sink_b_state = SinkState::Needs(amt - wrote_b); |
| 719 | Poll::Ready(Ok(wrote_b)) |
| 720 | } |
| 721 | Poll::Ready(Err(_)) => { |
| 722 | *this.sink_b_state = SinkState::Err; |
| 723 | // We need to convince the caller that we wrote the amount needed, |
| 724 | // so return that we wrote amt. |
| 725 | Poll::Ready(Ok(amt)) |
| 726 | } |
| 727 | Poll::Pending => Poll::Pending, |
| 728 | }; |
| 729 | |
| 730 | return res_b; |
| 731 | } |
| 732 | SinkState::Err | SinkState::Ready => { |
| 733 | // proceed |
| 734 | } |
| 735 | }; |
| 736 | |
| 737 | // Write to the first sink. |
| 738 | let res_a = this.sink_a.poll_write(cx, buf); |
| 739 | // save the result. |
| 740 | |
| 741 | // based on the result, choose how to write to the second sink. |
| 742 | match (res_a, *this.sink_b_state) { |
| 743 | (Poll::Ready(Ok(wrote_a)), SinkState::Ready) => { |
| 744 | let res_b = if buf.len() > wrote_a { |
| 745 | this.sink_b.poll_write(cx, &buf[..wrote_a]) |
| 746 | } else { |
| 747 | this.sink_b.poll_write(cx, buf) |
| 748 | }; |
| 749 | |
| 750 | match res_b { |
| 751 | Poll::Ready(Ok(wrote_b)) if wrote_b == wrote_a => { |
| 752 | *this.sink_b_state = SinkState::Ready; |
nothing calls this directly
no outgoing calls
no test coverage detected