[−][src]Struct lab_grader::results_file::ResultsFile
A CSV results file containing the results of the grading process.
Fields
path: PathBuf
Methods
impl ResultsFile
[src]
pub fn new<P: AsRef<Path>>(path: P) -> Result<ResultsFile, Error>
[src]
Creates a new ResultsFile
, creating the file if necessary.
A file will be created at the given path. 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. The extension will
be set to csv, possibly overwriting a provided extension. 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 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").unwrap(); assert!(rf.length() == 0);
pub fn append(&mut self, record: &str) -> Result<usize>
[src]
Appends the given &str
to the file, without 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!(rf.length() == 0); if let Err(e) = rf.append("here's some content\n") { // 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::new("as_csv.csv").unwrap(); assert!(rf.length() == 0); if let Err(e) = rf.write_csv(&point) { // Something went wrong, deal with it } assert!(rf.length() > 0);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ResultsFile
impl Send for ResultsFile
impl Sync for ResultsFile
impl Unpin for ResultsFile
impl UnwindSafe for ResultsFile
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,