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

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

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

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) -> &'static str {
        "x,y\n"
    }
}

let p = Point { x: 4, y: 8 };
assert_eq!(p.header(), "x,y\n");
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) -> &'static str

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

Loading content...

Implementors

impl AsCsv for Submission[src]

Loading content...