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 P: AsRef<Path> + Send + 'static,
18 {
new(options: StdOpenOptions, path: P) -> Self19     pub(crate) fn new(options: StdOpenOptions, path: P) -> Self {
20         OpenFuture { options, path }
21     }
22 }
23 
24 impl<P> Future for OpenFuture<P>
25 where P: AsRef<Path> + Send + 'static,
26 {
27     type Item = File;
28     type Error = io::Error;
29 
poll(&mut self) -> Poll<Self::Item, Self::Error>30     fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
31         let std = try_ready!(::blocking_io(|| {
32             self.options.open(&self.path)
33         }));
34 
35         let file = File::from_std(std);
36         Ok(file.into())
37     }
38 }
39