tokio_fs/
remove_file.rs

1use std::fs;
2use std::io;
3use std::path::Path;
4
5use futures::{Future, Poll};
6
7/// Removes a file from the filesystem.
8///
9/// Note that there is no
10/// guarantee that the file is immediately deleted (e.g. depending on
11/// platform, other open file descriptors may prevent immediate removal).
12///
13/// This is an async version of [`std::fs::remove_file`][std]
14///
15/// [std]: https://doc.rust-lang.org/std/fs/fn.remove_file.html
16pub fn remove_file<P: AsRef<Path>>(path: P) -> RemoveFileFuture<P> {
17    RemoveFileFuture::new(path)
18}
19
20/// Future returned by `remove_file`.
21#[derive(Debug)]
22pub struct RemoveFileFuture<P>
23where
24    P: AsRef<Path>,
25{
26    path: P,
27}
28
29impl<P> RemoveFileFuture<P>
30where
31    P: AsRef<Path>,
32{
33    fn new(path: P) -> RemoveFileFuture<P> {
34        RemoveFileFuture { path: path }
35    }
36}
37
38impl<P> Future for RemoveFileFuture<P>
39where
40    P: AsRef<Path>,
41{
42    type Item = ();
43    type Error = io::Error;
44
45    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
46        ::blocking_io(|| fs::remove_file(&self.path))
47    }
48}