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
//! What the borrow checker enforces, as doctests: each `compile_fail` block
//! has a twin that compiles, so that a block failing for an unrelated reason
//! (a typo) does not pass as the guarantee.
//!
//! A generator is not `Sync` (it is stateful), though it is `Send`:
//!
//! ```compile_fail
//! fn shared<T: Sync>(_: &T) {}
//! let g = isospec::OrderedGenerator::new(isospec::Iso::from_formula("H2O1").unwrap()).unwrap();
//! shared(&g);
//! ```
//! ```
//! fn sent<T: Send>(_: T) {}
//! let g = isospec::OrderedGenerator::new(isospec::Iso::from_formula("H2O1").unwrap()).unwrap();
//! sent(g);
//! ```
//!
//! An envelope's arrays are borrowed: they cannot outlive an operation that
//! may reorder or reallocate them.
//!
//! ```compile_fail
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let mut env = isospec::Envelope::from_total_prob(&iso, 0.9).unwrap();
//! let masses = env.masses();
//! env.sort_by_mass();
//! println!("{}", masses[0]);
//! ```
//! ```
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let mut env = isospec::Envelope::from_total_prob(&iso, 0.9).unwrap();
//! env.sort_by_mass();
//! let masses = env.masses();
//! println!("{}", masses[0]);
//! ```
//!
//! A generator takes its molecule: clone it to keep one.
//!
//! ```compile_fail
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let g = isospec::OrderedGenerator::new(iso).unwrap();
//! println!("{}", iso.monoisotopic_mass());
//! ```
//! ```
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let g = isospec::OrderedGenerator::new(iso.clone()).unwrap();
//! println!("{}", iso.monoisotopic_mass());
//! ```
//!
//! A generator's configuration is valid only until it moves on.
//!
//! ```compile_fail
//! let mut g = isospec::OrderedGenerator::new(isospec::Iso::from_formula("H2O1").unwrap()).unwrap();
//! g.advance().unwrap();
//! let conf = g.conf().unwrap();
//! g.advance().unwrap();
//! println!("{:?}", conf.counts());
//! ```
//! ```
//! let mut g = isospec::OrderedGenerator::new(isospec::Iso::from_formula("H2O1").unwrap()).unwrap();
//! g.advance().unwrap();
//! let conf = g.conf_owned().unwrap();
//! g.advance().unwrap();
//! println!("{:?}", conf.counts());
//! ```
//!
//! Two envelopes are compared through `&mut` both: the same one cannot be both.
//!
//! ```compile_fail
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let mut env = isospec::Envelope::from_total_prob(&iso, 0.9).unwrap();
//! env.wasserstein(&mut env).unwrap();
//! ```
//! ```
//! let iso = isospec::Iso::from_formula("H2O1").unwrap();
//! let mut env = isospec::Envelope::from_total_prob(&iso, 0.9).unwrap();
//! let mut copy = env.clone();
//! env.wasserstein(&mut copy).unwrap();
//! ```