1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::fs;
use std::io;
use std::marker::Unpin;
use std::path::{Path, PathBuf};
use std::str::FromStr;
#[cfg(target_os = "windows")]
use std::os::windows::io::RawHandle;
use heim_common::prelude::{Future, Stream, TryFutureExt};
use crate::shims;
#[derive(Debug)]
pub struct File(shims::fs::File);
impl File {
pub fn open<T>(path: T) -> impl Future<Output = io::Result<File>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::File::open(path).map_ok(File)
}
#[cfg(target_os = "windows")]
pub fn as_raw_handle(&self) -> RawHandle {
self.0.as_raw_handle()
}
}
pub fn path_exists<T>(path: T) -> impl Future<Output = bool>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::path_exists(path)
}
pub fn read_to_string<T>(path: T) -> impl Future<Output = io::Result<String>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::read_to_string(path)
}
pub fn read_lines<T>(path: T) -> impl Stream<Item = io::Result<String>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::read_lines(path)
}
pub fn read_first_line<T>(path: T) -> impl Future<Output = io::Result<String>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::read_first_line(path)
}
pub fn read_link<T>(path: T) -> impl Future<Output = io::Result<PathBuf>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::read_link(path)
}
pub fn read_dir<T>(path: T) -> impl Stream<Item = io::Result<fs::DirEntry>>
where
T: AsRef<Path> + Send + Unpin + 'static,
{
shims::fs::read_dir(path)
}
pub fn read_into<T, R, E>(path: T) -> impl Future<Output = Result<R, E>>
where
T: AsRef<Path> + Send + Unpin + 'static,
R: FromStr<Err = E>,
E: From<io::Error>,
{
shims::fs::read_into(path)
}
pub fn read_lines_into<T, R, E>(path: T) -> impl Stream<Item = Result<R, E>>
where
T: AsRef<Path> + Send + Unpin + 'static,
R: FromStr<Err = E>,
E: From<io::Error>,
{
shims::fs::read_lines_into(path)
}