rawfile.rs 486 B

123456789101112131415161718192021222324252627
  1. use core::ops::Deref;
  2. pub struct RawFile(usize);
  3. impl RawFile {
  4. pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<RawFile> {
  5. open(path, flags).map(RawFile)
  6. }
  7. pub fn dup(&self, buf: &[u8]) -> Result<RawFile> {
  8. dup(self.0, buf).map(RawFile)
  9. }
  10. }
  11. impl Drop for RawFile {
  12. fn drop(&mut self) {
  13. let _ = close(self.0);
  14. }
  15. }
  16. impl Deref for RawFile {
  17. type Target = usize;
  18. fn deref(&self) -> &usize {
  19. &self.0
  20. }
  21. }