exms/lib.rs
1//! Crate for getting fast and easy readable statistics and comparisons about
2//! exam results
3//!
4//! You can create a [Exam](exms::exam::Exam) object from a file. For the
5//! moment the only file formats supported are [JSON](#json) and [TOML](#toml)
6//! files.
7//!
8//! # Examples
9//!
10//! ```no_run
11//! use std::error::Error;
12//! use std::path::Path;
13//!
14//! use exms::error::ParseError;
15//! use exms::exam::Exam;
16//!
17//! fn main() -> Result<(), ParseError> {
18//! let file_path = Path::new("students.toml");
19//! let exam = Exam::from_file(&file_path)?;
20//!
21//! Ok(())
22//! }
23//! ```
24//!
25//! # Parsing from a file
26//!
27//! Each file that you want to parse should follow this format:
28//! It must contain a single field named `students` that contains key/value
29//! pairs for each student, where the key is the student's name and the value is
30//! the student's grade. The student's name should be a string, and the grade
31//! a number.
32//!
33//! The file can also contain an optional field named `details`. The currently
34//! possible options for this field are:
35//!
36//! - `max_grade` (number): The maximum possible grade of the exam. If no value
37//! is provided, the maximum grade will default to 10.
38//! - `name` (string): The name of the exam. If no value is provided, the file
39//! name will be used as the name.
40//!
41//!
42//! Here are some examples of valid files:
43//!
44//! JSON:
45//!
46//! ```json
47//! {
48//! "details": {
49//! "name": "Exam 1",
50//! "max_grade": 10
51//! },
52//!
53//! "students": {
54//! "Abad Martinez, Jose": 4.89,
55//! "Acevedo Fuenzalida, Ignacio Joaquin": 5.79,
56//! "Alba Gisbert, Diego": 7.11,
57//! "Alcántara Campillo, Irene": 4.41,
58//! }
59//! }
60//! ```
61//!
62//! TOML:
63//!
64//! ```toml
65//! [details] # This field is optional
66//! name = "Exam 1"
67//! max_grade = 10
68//!
69//! [students]
70//! "Abad Martinez, Jose" = 4.89
71//! "Acevedo Fuenzalida, Ignacio Joaquin" = 5.79
72//! "Alba Gisbert, Diego" = 7.11
73//! "Alcántara Campillo, Irene" = 4.41
74//! ```
75//!
76//! # Parsing other file formats
77//!
78//! Alternatively you can use your own parsing logic for any file you want to
79//! parse, parsing the file content into a `Vec<Student>` and creating a new
80//! `Exam` using the
81//! [Exam::new()](exam::Exam::new) function.
82//!
83//! ```compile_fail
84//! use std::error::Error;
85//! use std::path::Path;
86//!
87//! use exms::exam::{Exam, Student};
88//!
89//! fn main() -> Result<(), Box<dyn Error>> {
90//! let file_path = Path::new("my_file");
91//!
92//! // Here you should parse your file into a Vec<Student>
93//! let students: Vec<Student> = parse_file(&file_path)?;
94//! let exam = Exam::new(students);
95//!
96//! Ok(())
97//! }
98//! ```
99
100pub mod error;
101pub mod exam;