Mon, 24 Oct 2022 09:41:43 +0300
Allow step closure of AlgIterators to indicate succesfull termination or failure.
0 | 1 | use std::marker::PhantomData; |
2 | ||
3 | #[derive(Debug)] | |
4 | pub struct SupportId<S> { | |
5 | pub id : usize, | |
6 | _phantom : PhantomData<S> | |
7 | } | |
8 | ||
9 | // derive fails so need to do Copy and Clone manually | |
10 | ||
11 | impl<S> Clone for SupportId<S> { | |
12 | fn clone(&self) -> Self { | |
13 | SupportId { id : self.id, _phantom : PhantomData } | |
14 | } | |
15 | } | |
16 | ||
17 | impl<S> Copy for SupportId<S> {} | |
18 | ||
19 | impl<S> From<u32> for SupportId<S> { | |
20 | #[inline] | |
21 | fn from(id : u32) -> SupportId<S> { | |
22 | SupportId { id : id as usize, _phantom : PhantomData } | |
23 | } | |
24 | } | |
25 | ||
26 | impl<S> From<usize> for SupportId<S> { | |
27 | #[inline] | |
28 | fn from(id : usize) -> SupportId<S> { | |
29 | SupportId { id : id, _phantom : PhantomData } | |
30 | } | |
31 | } | |
32 | ||
33 | impl<S> Into<usize> for SupportId<S> { | |
34 | #[inline] | |
35 | fn into(self) -> usize { | |
36 | self.id | |
37 | } | |
38 | } | |
39 |