Last active
December 21, 2015 17:59
-
-
Save olsonjeffery/6344357 to your computer and use it in GitHub Desktop.
my pitch for FileInfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait FileInfo<'self> { | |
// stat/info-related methods | |
fn stat(&self) -> FileStat; | |
fn path(&self) -> Path; | |
fn exists(&self) -> bool; | |
// note that all of these involve opening/creating filestreams and they | |
// consume the FileInfo in the process | |
fn open(self, mode: FileMode, access: FileAccess) -> FileStream' | |
fn create(self); // implies a certain overload of open() above | |
fn truncate(self); // ... | |
fn other_open_scenarios(...); | |
// other stuff that falls into some other transaction category, but | |
// maybe not requiring consuming the value of the FileInfo as above.. | |
fn unlink(&self); | |
fn fsync(&self); | |
... | |
} | |
/// Impl on &PathLike (so &str and Path become FileInfos!) | |
/// | |
/// In this case, calling open() et al will consume the &PathLike and | |
/// yield a FileStream (which is also impls FileInfo!) | |
impl<'self> FileInfo for &'self PathLike { | |
... | |
} | |
/// Impl on FileStream (we get to use the internal fd for a bunch of | |
/// shortcuts on various calls (fstat vs stat, etc) | |
/// | |
/// In this case, calling open() et al will consume the FileStream | |
/// (thus closing it), before re-opening it with whatever permissions | |
/// are desired and yielding a new FileStream (which is also a FileInfo) | |
impl FileInfo for FileStream { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment