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
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
///Counter of Id for the PContent
pub struct PIdCounter{
///Current id of the counter
p_id: usize,
}
impl PIdCounter{
///Constructor of the PIdCounter
/// # Parameters
/// - `id` : first id of the counter
/// # Returns
/// Initialised PIdCounter
pub fn new(id: usize) -> Self{
PIdCounter {
p_id: id
}
}
///Set the current id
/// # Parameters
/// - `id` : new current id of the PIdCounter
pub fn set_id(&mut self, id: usize){
self.p_id = id;
}
///Get the current id
/// # Returns
/// Current id of the PContent to be created
pub fn get_id(&mut self) -> usize{
let current_id = self.p_id;
self.p_id += 1;
return current_id;
}
}
#[cfg(test)]
mod tests{
use super::*;
///Test the PIdCounter
#[test]
fn test_id_counter(){
let mut id = PIdCounter::new(42);
assert_eq!(id.get_id(), 42);
assert_eq!(id.get_id(), 43);
assert_eq!(id.get_id(), 44);
}
}