-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync_write_items.rs
47 lines (42 loc) · 1.14 KB
/
async_write_items.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::io::Result;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::task::{Context, Poll};
pub trait AsyncWriteItems<T: Unpin> {
fn poll_write_items(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
items: &[T],
) -> Poll<Result<usize>>;
}
macro_rules! deref_async_write_items {
($T:ty) => {
fn poll_write_items(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
items: &[$T],
) -> Poll<Result<usize>>
{
Pin::new(&mut **self).poll_write_items(cx, items)
}
}
}
impl<T: Unpin, A: ?Sized + AsyncWriteItems<T> + Unpin> AsyncWriteItems<T> for Box<A> {
deref_async_write_items!(T);
}
impl<T: Unpin, A: ?Sized + AsyncWriteItems<T> + Unpin> AsyncWriteItems<T> for &mut A {
deref_async_write_items!(T);
}
impl<T: Unpin, P> AsyncWriteItems<T> for Pin<P>
where
P: DerefMut + Unpin,
<P as Deref>::Target: AsyncWriteItems<T>,
{
fn poll_write_items(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
items: &[T],
) -> Poll<Result<usize>> {
self.get_mut().as_mut().poll_write_items(cx, items)
}
}