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
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::phighlighter::PLocation;
use crate::pcontent::PReferenceUrl;
use crate::pcontent::plabeler::PLabelId;
///Trait of a Lecture Backend
pub trait PAbstractLectureBackend{
///Create a new file
/// # Parameters
/// - `output_filename` : name of the file to write
/// - `title` : title of the section
/// - `location` : location of the current source file where this section was defined
/// - `prev_page` : previous page to visit
/// - `next_page` : next page to visit
fn create_file(&mut self, output_filename: &String, title: &String,
location: &PLocation,
prev_page: &String, next_page: &String);
///Write text in the current file
/// # Parameters
/// - `text` : text to write in the current file
fn write(&mut self, text: &String);
///Write a formula in html
/// # Parameters
/// - `formula` : formula to write in html
/// # Errors
/// This function will panic if there is a problem during the formula generation
fn write_formula(&mut self, formula: &String);
///Close the current file
fn close(&mut self);
}
///Definition of the trait for all lecture content
pub trait PAbstractContent{
///Say if the PContent has an embeded label
/// # Returns
/// True if the PContent has an embeded label, false otherwise
fn has_embeded_label(&self) -> bool;
///Get the reference url of the current PContent
/// # Parameters
/// - `current_file` : current output file of the PContent
/// - `id` : id of the current PContent
/// # Returns
/// Corresponding PReferenceUrl
fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl;
///Convert the current struct into html
/// # Parameters
/// - `backend` : backend which write a lecture in files
/// - `id` : id and label of the current PContent
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend;
}
//We can improve the to_html speed by using a stream (so no more copy between all content to be added)
//But the question is : does the fmt::Formatter a stream ?
//With the : fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
//We need a :
// use std::io::prelude::Write;
// use std::io::BufWriter;
// pub fn save_gnuplot(&self, filename: &Path) -> std::io::Result<()> {
// let mut file = BufWriter::new(std::fs::File::create(filename).unwrap());
// file.write(&format!("# PFunctionTimer : save performance of function '{}'\n", self.p_function_name).into_bytes())?;
// Ok(())
// }