Explorar o código

add rawfile.rs

Paul Sajna %!s(int64=7) %!d(string=hai) anos
pai
achega
4b1a1568bf
Modificáronse 1 ficheiros con 27 adicións e 0 borrados
  1. 27 0
      platform/src/rawfile.rs

+ 27 - 0
platform/src/rawfile.rs

@@ -0,0 +1,27 @@
+use core::ops::Deref;
+
+pub struct RawFile(usize);
+
+impl RawFile {
+    pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<RawFile> {
+        open(path, flags).map(RawFile)
+    }
+
+    pub fn dup(&self, buf: &[u8]) -> Result<RawFile> {
+        dup(self.0, buf).map(RawFile)
+    }
+}
+
+impl Drop for RawFile {
+    fn drop(&mut self) {
+        let _ = close(self.0);
+    }
+}
+
+impl Deref for RawFile {
+    type Target = usize;
+
+    fn deref(&self) -> &usize {
+        &self.0
+    }
+}