1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pub enum WeblabAttribute {
    Test,
    Library,
    Solution,
}

pub struct ProgrammingAssignment {
    pub title: &'static str,
    pub assignment_text: &'static str,

    pub library_visible: bool,
    pub spectest_stdout_visible: bool,
    pub test: &'static str,
    pub solution: &'static str,
    pub library: Option<&'static str>,
    pub test_template: &'static str,
    pub solution_template: &'static str,
    pub checklist: Option<Checklist>,
}

pub struct Checklist {
    pub items: Vec<&'static str>,
}

pub struct OpenQuestion {
    pub title: &'static str,

    pub assignment_text: &'static str,

    pub expected_answer: &'static str,
    pub checklist: Option<Checklist>,
}

pub struct MCQuestion {
    pub title: &'static str,
    pub assignment_text: &'static str,

    pub options: Vec<&'static str>,
    pub answer: usize,
}

pub enum WeblabAssignment {
    Programming(ProgrammingAssignment),
    Open(OpenQuestion),
    MultipleChoice(MCQuestion),
    Folder(WeblabFolder),
}

impl WeblabAssignment {
    pub fn title(&self) -> &str {
        match self {
            WeblabAssignment::Programming(ProgrammingAssignment { title, .. }) => title,
            WeblabAssignment::Open(OpenQuestion { title, .. }) => title,
            WeblabAssignment::MultipleChoice(MCQuestion { title, .. }) => title,
            WeblabAssignment::Folder(WeblabFolder { title, .. }) => title,
        }
    }
    pub fn assignment_text(&self) -> &str {
        match self {
            WeblabAssignment::Programming(ProgrammingAssignment {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::Open(OpenQuestion {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::MultipleChoice(MCQuestion {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::Folder(WeblabFolder {
                assignment_text, ..
            }) => assignment_text,
        }
    }
}

pub struct WeblabFolder {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub assignments: &'static [WeblabAssignment],
}