1 use super::File; 2 3 use futures::{Future, Poll}; 4 5 use std::io; 6 7 /// Future returned by `File::try_clone`. 8 /// 9 /// Clones a file handle into two file handles. 10 /// 11 /// # Panics 12 /// 13 /// Will panic if polled after returning an item or error. 14 #[derive(Debug)] 15 pub struct CloneFuture { 16 file: Option<File>, 17 } 18 19 impl CloneFuture { new(file: File) -> Self20 pub(crate) fn new(file: File) -> Self { 21 Self { file: Some(file) } 22 } 23 } 24 25 impl Future for CloneFuture { 26 type Item = (File, File); 27 type Error = (File, io::Error); 28 poll(&mut self) -> Poll<Self::Item, Self::Error>29 fn poll(&mut self) -> Poll<Self::Item, Self::Error> { 30 self.file 31 .as_mut() 32 .expect("Cannot poll `CloneFuture` after it resolves") 33 .poll_try_clone() 34 .map(|inner| inner.map(|cloned| (self.file.take().unwrap(), cloned))) 35 .map_err(|err| (self.file.take().unwrap(), err)) 36 } 37 } 38