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
use cap_primitives::fs::{reopen, OpenOptions};
#[cfg(any(feature = "std", feature = "async_std"))]
use io_lifetimes::AsFilelike;
#[cfg(feature = "async_std")]
use io_lifetimes::FromFilelike;
use std::io;
pub trait Reopen {
fn reopen(&self, options: &OpenOptions) -> io::Result<Self>
where
Self: Sized;
}
impl Reopen for std::fs::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
reopen(self, options)
}
}
#[cfg(feature = "std")]
impl Reopen for cap_std::fs::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
let file = reopen(
&AsFilelike::as_filelike_view::<std::fs::File>(self),
options,
)?;
Ok(Self::from_std(file))
}
}
#[cfg(all(feature = "std", feature = "fs_utf8"))]
impl Reopen for cap_std::fs_utf8::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
let file = reopen(&self.as_filelike_view::<std::fs::File>(), options)?;
Ok(Self::from_std(file))
}
}
#[cfg(feature = "async_std")]
impl Reopen for async_std::fs::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
let file = reopen(&self.as_filelike_view::<std::fs::File>(), options)?;
Ok(async_std::fs::File::from_into_filelike(file))
}
}
#[cfg(feature = "async_std")]
impl Reopen for cap_async_std::fs::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
let file = reopen(&self.as_filelike_view::<std::fs::File>(), options)?;
let std = async_std::fs::File::from_into_filelike(file);
Ok(Self::from_std(std))
}
}
#[cfg(all(feature = "async_std", feature = "fs_utf8"))]
impl Reopen for cap_async_std::fs_utf8::File {
#[inline]
fn reopen(&self, options: &OpenOptions) -> io::Result<Self> {
let file = reopen(&self.as_filelike_view::<std::fs::File>(), options)?;
let std = async_std::fs::File::from_into_filelike(file);
Ok(Self::from_std(std))
}
}