1
use crate::xinput::*;
2
use bytemuck::{Pod, Zeroable};
3

            
4

            
5

            
6
/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_state)\]
7
/// XINPUT_STATE
8
///
9
/// Packet number + [Gamepad] state.
10
#[derive(Clone, Copy, Debug)]
11
#[derive(Default, Pod, Zeroable)]
12
#[repr(C)] pub struct State {
13
    /// State packet number.
14
    /// The packet number indicates whether there have been any changes in the state of the controller.
15
    /// If `packet_number` is the same in sequentially returned [`State`] structures, the controller state has not changed.
16
    pub packet_number: u32,
17

            
18
    /// The gamepad state.
19
    pub gamepad:        Gamepad,
20
}
21

            
22
// N.B. these deref to Gamepad, not to XINPUT_STATE
23
impl std::ops::Deref for State {
24
    type Target = Gamepad;
25
1
    fn deref(&self) -> &Gamepad { &self.gamepad }
26
}
27

            
28
impl std::ops::DerefMut for State {
29
1
    fn deref_mut(&mut self) -> &mut Gamepad { &mut self.gamepad }
30
}
31

            
32
1
struct_mapping! {
33
    #[derive(unsafe { AsRef, AsMut, FromInto })]
34
1
    State => winapi::um::xinput::XINPUT_STATE {
35
1
        packet_number   => dwPacketNumber,
36
1
        gamepad         => Gamepad,
37
1
    }
38
1
}
39

            
40
1
#[test] fn test_traits_for_coverage() {
41
1
    let _state = State::default();
42
1
    let _state = State::zeroed();
43
1
    let mut _state = _state.clone();
44
1
    let _ = _state.left_trigger;
45
1
    _state.left_trigger = 42;
46
1
    dbg!(_state);
47
1
}
48

            
49
//#cpp2rust XINPUT_STATE                = xinput::State