1
2#[macro_use]
3extern crate cluStaticData;
4
5use cluStaticData::err::StaticErr;
6
7static_data! {
8 pub(crate) static ref DROPPER: MyDrop = MyDrop(0);
9}
10
11#[derive(Debug, PartialEq)]
12pub struct MyDrop(usize);
13
14impl Drop for MyDrop {
15 fn drop(&mut self) {
16 println!("line: {}, drop: MyDrop({})", line!(), self.0);
17 }
18}
19
20fn main() -> Result<(), StaticErr<MyDrop>> {
21 DROPPER.set(MyDrop(1))?;
22 println!("OK #0 this_value {:?}", DROPPER);
23
24 let err = DROPPER.set(MyDrop(2));
25 assert_eq!(err, Err(StaticErr::prev(MyDrop(2))) );
26 println!("OK #1 this_value {:?}", DROPPER);
27
28 let err = DROPPER.set(MyDrop(3));
29 assert_eq!(err, Err(StaticErr::prev(MyDrop(3))) );
30 println!("OK #2 this_value {:?}", DROPPER);
31
32 Ok( () )
33}