1 use super::File; 2 3 use futures::{Future, Poll}; 4 5 use std::fs::OpenOptions as StdOpenOptions; 6 use std::io; 7 use std::path::Path; 8 9 /// Future returned by `File::open` and resolves to a `File` instance. 10 #[derive(Debug)] 11 pub struct OpenFuture<P> { 12 options: StdOpenOptions, 13 path: P, 14 } 15 16 impl<P> OpenFuture<P> 17 where 18 P: AsRef<Path> + Send + 'static, 19 { new(options: StdOpenOptions, path: P) -> Self20 pub(crate) fn new(options: StdOpenOptions, path: P) -> Self { 21 OpenFuture { options, path } 22 } 23 } 24 25 impl<P> Future for OpenFuture<P> 26 where 27 P: AsRef<Path> + Send + 'static, 28 { 29 type Item = File; 30 type Error = io::Error; 31 poll(&mut self) -> Poll<Self::Item, Self::Error>32 fn poll(&mut self) -> Poll<Self::Item, Self::Error> { 33 let std = try_ready!(::blocking_io(|| self.options.open(&self.path))); 34 35 let file = File::from_std(std); 36 Ok(file.into()) 37 } 38 } 39