lazyfile.rs: Add documentation
This commit is contained in:
parent
64ee182d63
commit
434a766536
1 changed files with 22 additions and 0 deletions
|
@ -4,6 +4,11 @@ use std::io::{Seek, SeekFrom};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LazyFile type
|
||||||
|
*
|
||||||
|
* A lazy file is either absent, but a path to it is available, or it is present.
|
||||||
|
*/
|
||||||
pub enum LazyFile {
|
pub enum LazyFile {
|
||||||
Absent(PathBuf),
|
Absent(PathBuf),
|
||||||
File(File)
|
File(File)
|
||||||
|
@ -18,13 +23,24 @@ fn create_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<File> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LazyFile {
|
impl LazyFile {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new LazyFile instance from a Path
|
||||||
|
*/
|
||||||
pub fn new(p: PathBuf) -> LazyFile {
|
pub fn new(p: PathBuf) -> LazyFile {
|
||||||
LazyFile::Absent(p)
|
LazyFile::Absent(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new LazyFile instance from an already existing file
|
||||||
|
*/
|
||||||
pub fn new_with_file(f: File) -> LazyFile {
|
pub fn new_with_file(f: File) -> LazyFile {
|
||||||
LazyFile::File(f)
|
LazyFile::File(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file behind a LazyFile object
|
||||||
|
*/
|
||||||
pub fn get_file(&mut self) -> Result<&File, StoreError> {
|
pub fn get_file(&mut self) -> Result<&File, StoreError> {
|
||||||
match self.get_file_mut() {
|
match self.get_file_mut() {
|
||||||
Ok(file) => Ok(&*file),
|
Ok(file) => Ok(&*file),
|
||||||
|
@ -32,6 +48,9 @@ impl LazyFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mutable file behind a LazyFile object
|
||||||
|
*/
|
||||||
pub fn get_file_mut(&mut self) -> Result<&mut File, StoreError> {
|
pub fn get_file_mut(&mut self) -> Result<&mut File, StoreError> {
|
||||||
let file = match *self {
|
let file = match *self {
|
||||||
LazyFile::File(ref mut f) => return {
|
LazyFile::File(ref mut f) => return {
|
||||||
|
@ -56,6 +75,9 @@ impl LazyFile {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a file out of this LazyFile object
|
||||||
|
*/
|
||||||
pub fn create_file(&mut self) -> Result<&mut File, StoreError> {
|
pub fn create_file(&mut self) -> Result<&mut File, StoreError> {
|
||||||
let file = match *self {
|
let file = match *self {
|
||||||
LazyFile::File(ref mut f) => return Ok(f),
|
LazyFile::File(ref mut f) => return Ok(f),
|
||||||
|
|
Loading…
Reference in a new issue