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
bitflags::bitflags! {
/// Flags that are used by the methods in the ResourceManager traits
/// ([`sync::rm::ResourceManager`](sync/rm/trait.ResourceManager.html) and
/// [`a_sync::rm::ResourceManager`](a_sync/rm/trait.ResourceManager.html)).
#[derive(Default, Debug, PartialEq, Eq, Copy, Clone)]
pub struct Flags: u32 {
// / No resource manager feature selected.
// const NO_FLAGS = 0;
/// For `ResourceManager::xa_start()`:
/// indicates that the resource should associate with a previously suspended transaction.
const RESUME = 0x08_00_00_00;
/// For `ResourceManager::xa_start()`:
/// indicates that the transaction should associate with a transaction
/// previously seen by the server.
const JOIN = 0x00_20_00_00;
/// For `ResourceManager::xa_recover()`:
/// indicates that the server should start a new recovery scan.
const START_RECOVERY_SCAN = 0x01_00_00_00;
/// For `ResourceManager::xa_recover()`:
/// indicates that the server should end the current recovery scan.
const END_RECOVERY_SCAN = 0x00_80_00_00;
/// Indicates that the caller is using one-phase optimization. Seems not to be used.
const ONE_PHASE = 0x40_00_00_00;
/// For `ResourceManager::xa_end()`:
/// indicates that the transaction should be disassociated,
/// and that the work has failed
const FAIL = 0x20_00_00_00;
/// For `ResourceManager::xa_end()`:
/// indicates that the transaction should be disassociated,
/// and that the work has completed sucessfully.
const SUCCESS = 0x04_00_00_00;
/// For `ResourceManager::xa_end()`:
/// indicates that the resource should temporarily suspend the association
/// with the transaction.
const SUSPEND = 0x02_00_00_00;
}
}
impl Flags {
/// Returns `true` if only the flags in `other` are contained within `self`.
#[inline]
#[must_use]
pub fn contains_only(self, other: Flags) -> bool {
(self & !other).is_empty()
}
}
#[cfg(test)]
mod test {
use super::Flags;
#[test]
fn test1() {
assert_eq!(
Flags::RESUME | Flags::JOIN,
Flags::from_bits(0x08_20_00_00).unwrap()
);
assert_eq!((Flags::RESUME | Flags::JOIN).bits(), 0x08_20_00_00);
assert_eq!(Flags::default().bits(), 0);
let pattern = Flags::FAIL | Flags::SUCCESS | Flags::SUSPEND;
assert!((Flags::FAIL | Flags::SUCCESS).contains_only(pattern));
assert!(Flags::SUCCESS.contains_only(pattern));
assert!(Flags::default().contains_only(pattern));
assert!(!Flags::RESUME.contains_only(pattern));
}
}