net-relay 0.1.3

A set of types for network relay.
Documentation
use crate::{Error, Relay};
use std::pin::Pin;
use std::task::{Context, Poll};

pub trait RelayExt: Relay {
    fn run(&mut self) -> Run<'_, Self> {
        Run { r: self }
    }
}

impl<R: Relay + ?Sized> RelayExt for R {}

pub struct Run<'a, R: Relay + ?Sized> {
    r: &'a mut R,
}

impl<'a, S: Relay + ?Sized> Future for Run<'a, S> {
    type Output = Result<(), Error>;

    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        let r = unsafe { self.map_unchecked_mut(|s| s.r) };
        r.poll_run(cx)
    }
}