[][src]Trait lab_grader::results_file::AsCsv

pub trait AsCsv {
    fn as_csv(&self) -> String;
fn filename(&self) -> String;
fn header(&self) -> String; }

Trait to convert a struct to csv (comma separated values).

You should not append a newline for any of these functions.

Example Implementation

use lab_grader::results_file::AsCsv;

// A dummy struct so we can impl AsCsv
pub struct Point {
    x: i32,
    y: i32
}

impl AsCsv for Point {
    fn as_csv(&self) -> String {
        format!("{},{}", self.x, self.y)
    }

    fn filename(&self) -> String {
        String::from("points.csv")
    }

    fn header(&self) -> String {
        String::from("x,y")
    }
}

let p = Point { x: 4, y: 8 };
assert_eq!(p.header(), "x,y");
assert_eq!(p.filename(), "points.csv");
assert_eq!(p.as_csv(), "4,8");

Required methods

fn as_csv(&self) -> String

The item in CSV format. This should not append a newline.

fn filename(&self) -> String

The filename where this type should be saved. Usually this should just be <item>.csv

fn header(&self) -> String

The header for the csv file. Should match the fields in as_csv()

Loading content...

Implementors

impl AsCsv for Submission[src]

fn as_csv(&self) -> String[src]

Returns the submission's values in csv format. The TestData atttached will be sorted alphabetically by key.

fn filename(&self) -> String[src]

Returns the filename to use when writing submissions to disk

fn header(&self) -> String[src]

Returns a header of all the fields, matching the data in as_csv

impl AsCsv for TestData[src]

fn as_csv(&self) -> String[src]

Returns the test data, serialized to a csv string. It will be sorted alphabetically by key.

fn filename(&self) -> String[src]

Returns the filename that the ResultsFile uses as its output

This probably shouldn't get used for test data, as it will be written as part of a submission, not on it's own.

fn header(&self) -> String[src]

Returns a header to write to a csv file. This should match the fields in as_csv above.

Loading content...