karma_p2p/futures/
set_remote_addr.rs

1use std::{
2    mem,
3    pin::Pin,
4    task::{Context, Poll},
5};
6
7use futures_lite::Future;
8
9use crate::P2pSocket;
10
11pub struct SetRemoteAddr<'a, T: P2pSocket> {
12    pub socket: &'a T,
13    pub remote: Option<T::Addr>,
14}
15
16impl<'a, T> Future for SetRemoteAddr<'a, T>
17where
18    T: P2pSocket + Unpin,
19    T::Addr: Unpin,
20{
21    type Output = Result<(), T::Error>;
22
23    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
24        let mut this = self;
25
26        let opt_remote = mem::replace(&mut this.remote, None);
27        let socket = &*this.socket;
28
29        Pin::new(socket).poll_set_remote_addr(cx, opt_remote.unwrap())
30    }
31}