Auto merge of #128 - matthiasbeyer:libimagstore/source-doc, r=matthiasbeyer

Libimagstore/source doc

Add documentation to libimagstore types.
This commit is contained in:
Homu 2016-01-21 22:55:41 -08:00
commit 5dada9a753
5 changed files with 54 additions and 0 deletions

View file

@ -1 +1,4 @@
/**
* EntryContent type
*/
pub type EntryContent = String; pub type EntryContent = String;

View file

@ -2,6 +2,11 @@ use header::EntryHeader;
use content::EntryContent; use content::EntryContent;
use store::StoreId; use store::StoreId;
/**
* An Entry of the store
*
* Contains location, header and content part.
*/
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Entry { pub struct Entry {
location: StoreId, location: StoreId,

View file

@ -4,6 +4,9 @@ use std::fmt::Formatter;
use std::fmt::Error as FmtError; use std::fmt::Error as FmtError;
use std::clone::Clone; use std::clone::Clone;
/**
* Kind of store error
*/
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum StoreErrorKind { pub enum StoreErrorKind {
FileError, FileError,
@ -35,6 +38,9 @@ impl Display for StoreErrorKind {
} }
/**
* Store error type
*/
#[derive(Debug)] #[derive(Debug)]
pub struct StoreError { pub struct StoreError {
err_type: StoreErrorKind, err_type: StoreErrorKind,
@ -43,6 +49,9 @@ pub struct StoreError {
impl StoreError { impl StoreError {
/**
* Build a new StoreError from an StoreErrorKind, optionally with cause
*/
pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>) pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>)
-> StoreError -> StoreError
{ {
@ -52,6 +61,9 @@ impl StoreError {
} }
} }
/**
* Get the error type of this StoreError
*/
pub fn err_type(&self) -> StoreErrorKind { pub fn err_type(&self) -> StoreErrorKind {
self.err_type.clone() self.err_type.clone()
} }

View file

@ -1,5 +1,11 @@
use toml::Table; use toml::Table;
/**
* EntryHeader
*
* This is basically a wrapper around toml::Table which provides convenience to the user of the
* librray.
*/
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct EntryHeader { pub struct EntryHeader {
toml: Table, toml: Table,
@ -7,12 +13,18 @@ pub struct EntryHeader {
impl EntryHeader { impl EntryHeader {
/**
* Get a new header object with a already-filled toml table
*/
pub fn new(toml: Table) -> EntryHeader { pub fn new(toml: Table) -> EntryHeader {
EntryHeader { EntryHeader {
toml: toml, toml: toml,
} }
} }
/**
* Get the table which lives in the background
*/
pub fn toml(&self) -> &Table { pub fn toml(&self) -> &Table {
&self.toml &self.toml
} }

View file

@ -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),