[−][src]Struct rubric::results_file::ResultsFile
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]
path: P,
header: S
) -> Result<ResultsFile, Error>
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 rubric::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
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, I> AsResult<T, I> for T where
I: Input,
I: Input,
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> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
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]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,