[][src]Struct lab_grader::results_file::ResultsFile

pub struct ResultsFile {
    pub path: PathBuf,
    // some fields omitted
}

A CSV results file containing the results of the grading process.

Fields

path: PathBuf

Implementations

impl ResultsFile[src]

pub fn new<P: AsRef<Path>, S: AsRef<str>>(
    path: P,
    header: S
) -> Result<ResultsFile, Error>
[src]

Creates a new ResultsFile, creating the file if necessary.

Note: You probably shouldn't use this. Instead, try ResultsFile::for_item below.

A file will be created at the given path, and write the given header. The path provided is anything that can be converted from to a Path, so Path, PathBuf, or &str will all work.

If the file already exists, it will still use that file. This will return a std::io::Error if the file, for one reason or another, cannot be created.

Example

use lab_grader::results_file::ResultsFile;

let rf = ResultsFile::new("my_results_file.csv", "").expect("Couldn't create results file");

pub fn for_item<I: AsCsv>(item: &I) -> Result<ResultsFile, Error>[src]

pub fn length(&self) -> u64[src]

Returns the length of the results file in bytes.

This will panic if the file doesn't exist or if this process does not have permission to access it. The file is created by this process when making a new ResultsFile, so as long as you don't change the file permissions or delete the file while your program is running, you'll be fine.

Example

let rf = ResultsFile::new("file.csv", "123").unwrap();

assert_eq!(rf.length(), 4);

pub fn append(&mut self, record: &str) -> Result<usize>[src]

Appends the given &str to the file, with a trailing newline.

Returns an io::Result containing the size written. ResultsFile must be mutable.

Example

let mut rf = ResultsFile::new("append.csv", "").unwrap();

assert_eq!(rf.length(), 1);
if let Err(e) = rf.append("here's some content") {
    // Something went wrong, deal with it
}
assert!(rf.length() > 0);

pub fn write_csv<R: AsCsv>(&mut self, record: &R) -> Result<usize>[src]

Writes an item to the csv file in csv format. This item must implement the AsCsv trait.

This method does append a newline after the record is written. Again, the results file will need to be mutable.

Example

// A custom struct that implements AsCsv
let point = Point { x: 6, y: 19 };

let mut rf = ResultsFile::for_item(&point).unwrap();
assert_eq!(rf.length(), 4);
if let Err(e) = rf.write_csv(&point) {
    // Something went wrong, deal with it
}
assert!(rf.length() > 4);

Trait Implementations

impl Debug for ResultsFile[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoCollection<T> for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,