1
2use std::fs::File;
3use std::fmt::{Debug, Formatter, Error};
4use std::io::Result;
5pub use std::io::Write;
6pub use std::io::Read;
7pub use std::path::Path;
8pub use std::io::Seek;
9pub use std::io::SeekFrom;
10
11pub struct WFile { f: File }
12impl WFile {
13 pub fn sync_all(&self) -> Result<()> {
14 self.f.sync_all()
15 }
16 pub fn sync_data(&self) -> Result<()> {
17 self.f.sync_data()
18 }
19 pub fn set_len(&self, size: u64) -> Result<()> {
20 self.f.set_len(size)
21 }
22 pub fn metadata(&self) -> Result<std::fs::Metadata> {
23 self.f.metadata()
24 }
25}
26
27pub struct RFile { f: File }
28impl RFile {
29 pub fn metadata(&self) -> Result<std::fs::Metadata> {
30 self.f.metadata()
31 }
32}
33
34
35impl Debug for WFile {
36 fn fmt(&self, fmtr: &mut Formatter) -> std::result::Result<(), Error> {
37 self.f.fmt(fmtr)
38 }
39}
40
41impl Debug for RFile {
42 fn fmt(&self, fmtr: &mut Formatter) -> std::result::Result<(), Error> {
43 self.f.fmt(fmtr)
44 }
45}
46
47impl Seek for RFile {
48 fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
49 self.f.seek(pos)
50 }
51}
52
53impl Seek for WFile {
54 fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
55 self.f.seek(pos)
56 }
57}
58
59impl Write for WFile {
60 fn write(&mut self, buf: &[u8]) -> Result<usize> {
61 self.f.write(buf)
62 }
63 fn flush(&mut self) -> Result<()> {
64 self.f.flush()
65 }
66 fn write_all(&mut self, buf: &[u8]) -> Result<()> {
67 self.f.write_all(buf)
68 }
69 fn write_fmt(&mut self, fmt: std::fmt::Arguments) -> Result<()> {
70 self.f.write_fmt(fmt)
71 }
72 fn by_ref(&mut self) -> &mut Self {
73 self
74 }
75}
79
80impl Read for RFile {
81 fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
82 self.f.read(buf)
83 }
84 fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
85 self.f.read_to_end(buf)
86 }
87 fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
88 self.f.read_to_string(buf)
89 }
90fn by_ref(&mut self) -> &mut Self {
94 self
95 }
96
97}
103
104pub fn open<P: AsRef<Path>>(path: P) -> Result<RFile> {
107 Ok(RFile {
108 f: try!(File::open(path))
109 })
110}
111
112pub fn create<P: AsRef<Path>>(path: P) -> Result<WFile> {
115 Ok(WFile {
116 f: try!(File::create(path))
117 })
118}