1
#[allow(unused_imports)]
2
pub use super::*;
3
#[cfg(test)]
4
mod autotest_generated {
5
    use super::*;
6

            
7
    /// Every `GamepadButton`, in discriminant order. The order here is also
8
    /// the asserted bit order — see `bit_matches_documented_abi`.
9
    const ALL_BUTTONS: [GamepadButton; 17] = [
10
        GamepadButton::South,
11
        GamepadButton::East,
12
        GamepadButton::North,
13
        GamepadButton::West,
14
        GamepadButton::LeftBumper,
15
        GamepadButton::RightBumper,
16
        GamepadButton::LeftTrigger,
17
        GamepadButton::RightTrigger,
18
        GamepadButton::Select,
19
        GamepadButton::Start,
20
        GamepadButton::Mode,
21
        GamepadButton::LeftThumb,
22
        GamepadButton::RightThumb,
23
        GamepadButton::DPadUp,
24
        GamepadButton::DPadDown,
25
        GamepadButton::DPadLeft,
26
        GamepadButton::DPadRight,
27
    ];
28

            
29
    const ALL_AXES: [GamepadAxis; 6] = [
30
        GamepadAxis::LeftStickX,
31
        GamepadAxis::LeftStickY,
32
        GamepadAxis::RightStickX,
33
        GamepadAxis::RightStickY,
34
        GamepadAxis::LeftZ,
35
        GamepadAxis::RightZ,
36
    ];
37

            
38
    /// Bitset of every defined button — bits 0..=16.
39
    const ALL_BUTTONS_MASK: u32 = 0x0001_FFFF;
40

            
41
    /// Writes `v` into the field that `GamepadState::axis` reads for `axis`.
42
    /// Deliberately mirrors `axis()`; a mis-mapping here would still be caught
43
    /// by `axis_reads_each_field_uniquely`, which pokes the fields directly.
44
    fn set_axis(s: &mut GamepadState, axis: GamepadAxis, v: f32) {
45
        match axis {
46
            GamepadAxis::LeftStickX => s.left_stick_x = v,
47
            GamepadAxis::LeftStickY => s.left_stick_y = v,
48
            GamepadAxis::RightStickX => s.right_stick_x = v,
49
            GamepadAxis::RightStickY => s.right_stick_y = v,
50
            GamepadAxis::LeftZ => s.left_z = v,
51
            GamepadAxis::RightZ => s.right_z = v,
52
        }
53
    }
54

            
55
    // ------------------------------------------------------------------
56
    // GamepadButton::bit  (other)
57
    // ------------------------------------------------------------------
58

            
59
    /// no_panic_smoke + shift-overflow guard: `bit()` is `1u32 << (self as
60
    /// u32)`, which is UB / a panic in debug the moment a discriminant reaches
61
    /// 32. Pin the discriminants to a contiguous 0..17 so adding an 18th..32nd
62
    /// button stays safe and a 33rd fails HERE rather than at a user's shift.
63
    #[test]
64
    fn bit_discriminants_are_contiguous_and_shift_safe() {
65
        for (i, b) in ALL_BUTTONS.iter().enumerate() {
66
            let d = *b as u32;
67
            assert_eq!(
68
                d, i as u32,
69
                "{b:?} has discriminant {d}, expected {i} — the bitset in GamepadState::buttons \
70
                 assumes contiguous discriminants"
71
            );
72
            assert!(
73
                d < 32,
74
                "{b:?} discriminant {d} would overflow `1u32 << d` in bit()"
75
            );
76
        }
77
    }
78

            
79
    /// The ABI the doc comment promises ("the discriminant order is also the
80
    /// bit position … don't reorder without bumping the ABI"). Hard-coded so a
81
    /// reorder is a loud test failure, not a silent remap of every FFI client's
82
    /// button bits.
83
    #[test]
84
    fn bit_matches_documented_abi() {
85
        assert_eq!(GamepadButton::South.bit(), 1 << 0);
86
        assert_eq!(GamepadButton::East.bit(), 1 << 1);
87
        assert_eq!(GamepadButton::North.bit(), 1 << 2);
88
        assert_eq!(GamepadButton::West.bit(), 1 << 3);
89
        assert_eq!(GamepadButton::LeftBumper.bit(), 1 << 4);
90
        assert_eq!(GamepadButton::RightBumper.bit(), 1 << 5);
91
        assert_eq!(GamepadButton::LeftTrigger.bit(), 1 << 6);
92
        assert_eq!(GamepadButton::RightTrigger.bit(), 1 << 7);
93
        assert_eq!(GamepadButton::Select.bit(), 1 << 8);
94
        assert_eq!(GamepadButton::Start.bit(), 1 << 9);
95
        assert_eq!(GamepadButton::Mode.bit(), 1 << 10);
96
        assert_eq!(GamepadButton::LeftThumb.bit(), 1 << 11);
97
        assert_eq!(GamepadButton::RightThumb.bit(), 1 << 12);
98
        assert_eq!(GamepadButton::DPadUp.bit(), 1 << 13);
99
        assert_eq!(GamepadButton::DPadDown.bit(), 1 << 14);
100
        assert_eq!(GamepadButton::DPadLeft.bit(), 1 << 15);
101
        assert_eq!(GamepadButton::DPadRight.bit(), 1 << 16);
102
    }
103

            
104
    /// invariant: each bit is a distinct, non-zero power of two. Two buttons
105
    /// sharing a bit would make `is_pressed` report a phantom press.
106
    #[test]
107
    fn bit_is_a_distinct_power_of_two() {
108
        let mut seen = 0u32;
109
        for b in ALL_BUTTONS {
110
            let bit = b.bit();
111
            assert_ne!(bit, 0, "{b:?} maps to bit 0");
112
            assert_eq!(
113
                bit.count_ones(),
114
                1,
115
                "{b:?} bit {bit:#x} is not a single bit"
116
            );
117
            assert_eq!(
118
                seen & bit,
119
                0,
120
                "{b:?} bit {bit:#x} collides with an earlier button"
121
            );
122
            seen |= bit;
123
        }
124
        assert_eq!(seen, ALL_BUTTONS_MASK);
125
        assert_eq!(seen.count_ones(), ALL_BUTTONS.len() as u32);
126
    }
127

            
128
    /// `bit()` is `const fn` — usable in a `const` item / array length. A
129
    /// non-const-evaluable body (or an overflowing shift, which is a hard
130
    /// compile error in const context) fails to build.
131
    #[test]
132
    fn bit_is_const_evaluable() {
133
        const SOUTH: u32 = GamepadButton::South.bit();
134
        const DPAD_RIGHT: u32 = GamepadButton::DPadRight.bit();
135
        assert_eq!(SOUTH, 1);
136
        assert_eq!(DPAD_RIGHT, 65_536);
137
    }
138

            
139
    // ------------------------------------------------------------------
140
    // GamepadState::empty  (constructor)
141
    // ------------------------------------------------------------------
142

            
143
    /// no_panic + invariants_hold: extreme ids (0, 1, MAX/2, MAX) round-trip
144
    /// into the state unchanged and every other field is the documented zero.
145
    #[test]
146
    fn empty_preserves_id_and_zeroes_everything_else() {
147
        for raw in [0, 1, u32::MAX / 2, u32::MAX - 1, u32::MAX] {
148
            let s = GamepadState::empty(GamepadId { id: raw });
149
            assert_eq!(s.id, GamepadId { id: raw });
150
            assert_eq!(s.id.id, raw);
151
            assert!(!s.connected, "empty() must start disconnected");
152
            assert_eq!(s.buttons, 0);
153
        }
154
    }
155

            
156
    /// default_is_neutral: an empty state is the neutral element — no button
157
    /// reads as pressed and every axis is exactly *positive* zero. The
158
    /// `to_bits()` check is the point: a `-0.0` would still compare `== 0.0`
159
    /// yet flips the sign of anything a caller multiplies by it.
160
    #[test]
161
    fn empty_is_neutral_for_every_button_and_axis() {
162
        let s = GamepadState::empty(GamepadId { id: 42 });
163
        for b in ALL_BUTTONS {
164
            assert!(!s.is_pressed(b), "{b:?} reads as pressed in an empty state");
165
        }
166
        for a in ALL_AXES {
167
            assert_eq!(
168
                s.axis(a).to_bits(),
169
                0.0f32.to_bits(),
170
                "axis {a:?} of an empty state is not +0.0 (got {})",
171
                s.axis(a)
172
            );
173
        }
174
    }
175

            
176
    /// invariant: `empty()` is a pure function of `id` — same id gives an
177
    /// equal state, a different id gives an unequal one (so a stale slot for
178
    /// pad 0 can't be mistaken for pad 1's).
179
    #[test]
180
    fn empty_is_deterministic_and_id_discriminating() {
181
        let a = GamepadState::empty(GamepadId { id: 7 });
182
        let b = GamepadState::empty(GamepadId { id: 7 });
183
        let c = GamepadState::empty(GamepadId { id: 8 });
184
        assert_eq!(a, b);
185
        assert_ne!(a, c);
186
    }
187

            
188
    /// `empty()` is `const fn`, so a backend can build a static slot table.
189
    #[test]
190
    fn empty_is_const_evaluable() {
191
        const S: GamepadState = GamepadState::empty(GamepadId { id: u32::MAX });
192
        assert_eq!(S.id.id, u32::MAX);
193
        assert_eq!(S.buttons, 0);
194
        const _: () = assert!(!S.connected);
195
    }
196

            
197
    // ------------------------------------------------------------------
198
    // GamepadState::is_pressed  (predicate)
199
    // ------------------------------------------------------------------
200

            
201
    /// basic_true_false + isolation: with exactly one bit set, that button —
202
    /// and *only* that button — reads as pressed. Catches an off-by-one shift
203
    /// or a bit collision that a single known-true case would miss.
204
    #[test]
205
    fn is_pressed_isolates_each_single_bit() {
206
        for pressed in ALL_BUTTONS {
207
            let mut s = GamepadState::empty(GamepadId { id: 0 });
208
            s.buttons = pressed.bit();
209
            for other in ALL_BUTTONS {
210
                assert_eq!(
211
                    s.is_pressed(other),
212
                    other == pressed,
213
                    "buttons={:#x}: is_pressed({other:?}) disagrees with the only pressed button \
214
                     {pressed:?}",
215
                    s.buttons
216
                );
217
            }
218
        }
219
    }
220

            
221
    /// edge_inputs: the two saturating bitsets. `0` = nothing pressed,
222
    /// `u32::MAX` = everything pressed. Both are deterministic, neither panics.
223
    #[test]
224
    fn is_pressed_handles_empty_and_full_bitsets() {
225
        let mut s = GamepadState::empty(GamepadId { id: 0 });
226

            
227
        s.buttons = 0;
228
        for b in ALL_BUTTONS {
229
            assert!(!s.is_pressed(b), "{b:?} pressed with buttons == 0");
230
        }
231

            
232
        s.buttons = u32::MAX;
233
        for b in ALL_BUTTONS {
234
            assert!(
235
                s.is_pressed(b),
236
                "{b:?} not pressed with buttons == u32::MAX"
237
            );
238
        }
239
    }
240

            
241
    /// Adversarial: a backend (or a hostile FFI caller) writes junk into the
242
    /// 15 *reserved* high bits, 17..=31. No defined button may light up — the
243
    /// mask is per-button, so garbage outside the defined range must be inert.
244
    #[test]
245
    fn is_pressed_ignores_reserved_high_bits() {
246
        let mut s = GamepadState::empty(GamepadId { id: 0 });
247
        for junk in [
248
            !ALL_BUTTONS_MASK, // every reserved bit
249
            1 << 17,           // the first reserved bit
250
            1 << 31,           // the sign bit
251
            0xDEAD_0000 & !ALL_BUTTONS_MASK,
252
        ] {
253
            assert_eq!(
254
                junk & ALL_BUTTONS_MASK,
255
                0,
256
                "test vector {junk:#x} is not reserved-only"
257
            );
258
            s.buttons = junk;
259
            for b in ALL_BUTTONS {
260
                assert!(
261
                    !s.is_pressed(b),
262
                    "reserved-bit junk {junk:#x} made {b:?} read as pressed"
263
                );
264
            }
265
        }
266
    }
267

            
268
    /// round-trip: encode a button set into the bitset, decode it back through
269
    /// `is_pressed` — the decoded set must equal the encoded one, and
270
    /// re-encoding must reproduce the exact same bits (encode == decode).
271
    #[test]
272
    fn is_pressed_bitset_roundtrips() {
273
        let subsets: [&[GamepadButton]; 5] = [
274
            &[],
275
            &[GamepadButton::South],
276
            &[GamepadButton::DPadRight],
277
            &[
278
                GamepadButton::South,
279
                GamepadButton::DPadRight,
280
                GamepadButton::Mode,
281
            ],
282
            &ALL_BUTTONS,
283
        ];
284

            
285
        for subset in subsets {
286
            let encoded = subset.iter().fold(0u32, |acc, b| acc | b.bit());
287

            
288
            let mut s = GamepadState::empty(GamepadId { id: 3 });
289
            s.buttons = encoded;
290

            
291
            // Decode through the predicate, then re-encode from what we decoded.
292
            let mut re_encoded = 0u32;
293
            for (i, b) in ALL_BUTTONS.iter().enumerate() {
294
                let decoded = s.is_pressed(*b);
295
                assert_eq!(
296
                    decoded,
297
                    subset.contains(b),
298
                    "decode of {encoded:#x}: is_pressed({b:?}) disagrees with the encoded subset \
299
                     (bit {i})"
300
                );
301
                if decoded {
302
                    re_encoded |= b.bit();
303
                }
304
            }
305
            assert_eq!(
306
                re_encoded, encoded,
307
                "re-encode of {encoded:#x} is not bit-stable"
308
            );
309
        }
310
    }
311

            
312
    /// `is_pressed` is `const fn` and takes `&self` — usable on a const state.
313
    #[test]
314
    fn is_pressed_is_const_evaluable() {
315
        const S: GamepadState = GamepadState {
316
            id: GamepadId { id: 0 },
317
            connected: true,
318
            buttons: 0b101, // South (bit 0) | North (bit 2)
319
            left_stick_x: 0.0,
320
            left_stick_y: 0.0,
321
            right_stick_x: 0.0,
322
            right_stick_y: 0.0,
323
            left_z: 0.0,
324
            right_z: 0.0,
325
            // Listed explicitly: this is a `const`, and
326
            // `Default::default()` is not a const fn.
327
            battery: -1.0,
328
            touchpad_x: 0.0,
329
            touchpad_y: 0.0,
330
            touchpad2_x: 0.0,
331
            touchpad2_y: 0.0,
332
            touchpad_active: false,
333
            touchpad2_active: false,
334
            gyro_x: 0.0,
335
            gyro_y: 0.0,
336
            gyro_z: 0.0,
337
            accel_x: 0.0,
338
            accel_y: 0.0,
339
            accel_z: 0.0,
340
        };
341
        const SOUTH: bool = S.is_pressed(GamepadButton::South);
342
        const EAST: bool = S.is_pressed(GamepadButton::East);
343
        const NORTH: bool = S.is_pressed(GamepadButton::North);
344
        const _: () = assert!(SOUTH && !EAST && NORTH);
345
    }
346

            
347
    /// invariant: `is_pressed` is a read-only view — polling every button
348
    /// leaves the snapshot byte-identical.
349
    #[test]
350
    fn is_pressed_does_not_mutate_the_snapshot() {
351
        let mut s = GamepadState::empty(GamepadId { id: 9 });
352
        s.buttons = 0x1_0F0F & ALL_BUTTONS_MASK;
353
        let before = s;
354
        for b in ALL_BUTTONS {
355
            let _ = s.is_pressed(b);
356
        }
357
        assert_eq!(s, before);
358
    }
359

            
360
    // ------------------------------------------------------------------
361
    // GamepadState::axis  (other)
362
    // ------------------------------------------------------------------
363

            
364
    /// The copy-paste trap: `axis()` is a six-arm match over six near-identical
365
    /// fields. Give every field a unique sentinel and poke the fields directly
366
    /// (never through a helper that could share the same bug), so any two arms
367
    /// reading the same field — or reading each other's — fails here.
368
    #[test]
369
    fn axis_reads_each_field_uniquely() {
370
        let s = GamepadState {
371
            id: GamepadId { id: 1 },
372
            connected: true,
373
            buttons: 0,
374
            left_stick_x: 1.0,
375
            left_stick_y: 2.0,
376
            right_stick_x: 3.0,
377
            right_stick_y: 4.0,
378
            left_z: 5.0,
379
            right_z: 6.0,
380
            // Fields this site does not set. Growing GamepadState must not
381
            // break every construction of it.
382
            ..Default::default()
383
        };
384
        assert_eq!(s.axis(GamepadAxis::LeftStickX).to_bits(), 1.0f32.to_bits());
385
        assert_eq!(s.axis(GamepadAxis::LeftStickY).to_bits(), 2.0f32.to_bits());
386
        assert_eq!(s.axis(GamepadAxis::RightStickX).to_bits(), 3.0f32.to_bits());
387
        assert_eq!(s.axis(GamepadAxis::RightStickY).to_bits(), 4.0f32.to_bits());
388
        assert_eq!(s.axis(GamepadAxis::LeftZ).to_bits(), 5.0f32.to_bits());
389
        assert_eq!(s.axis(GamepadAxis::RightZ).to_bits(), 6.0f32.to_bits());
390

            
391
        // …and every axis is pairwise distinct, so no two arms alias one field.
392
        for (i, a) in ALL_AXES.iter().enumerate() {
393
            for b in ALL_AXES.iter().skip(i + 1) {
394
                assert_ne!(
395
                    s.axis(*a).to_bits(),
396
                    s.axis(*b).to_bits(),
397
                    "axes {a:?} and {b:?} read the same field"
398
                );
399
            }
400
        }
401
    }
402

            
403
    /// no_panic_smoke over the nasty floats: NaN (incl. a signalling payload),
404
    /// ±inf, ±0.0, subnormals, MIN/MAX. `axis()` is a getter, so it must hand
405
    /// each one back *bit-for-bit* — no clamping, no NaN canonicalisation,
406
    /// no sign-of-zero loss (a `-0.0` silently flipping to `+0.0` would change
407
    /// the direction of a caller's `v.signum()` deadzone check).
408
    #[test]
409
    fn axis_returns_extreme_floats_bit_exact() {
410
        let nasty: [f32; 12] = [
411
            f32::NAN,
412
            -f32::NAN,
413
            f32::from_bits(0x7F80_0001), // signalling NaN payload
414
            f32::INFINITY,
415
            f32::NEG_INFINITY,
416
            0.0,
417
            -0.0,
418
            f32::MIN_POSITIVE,
419
            f32::from_bits(1), // smallest subnormal
420
            -1.0,
421
            f32::MIN,
422
            f32::MAX,
423
        ];
424

            
425
        for a in ALL_AXES {
426
            for v in nasty {
427
                let mut s = GamepadState::empty(GamepadId { id: 0 });
428
                set_axis(&mut s, a, v);
429
                assert_eq!(
430
                    s.axis(a).to_bits(),
431
                    v.to_bits(),
432
                    "axis {a:?} did not return {v:?} bit-exactly (bits {:#x} vs {:#x})",
433
                    s.axis(a).to_bits(),
434
                    v.to_bits()
435
                );
436
            }
437
            // Writing one axis must not disturb the other five.
438
            let mut s = GamepadState::empty(GamepadId { id: 0 });
439
            set_axis(&mut s, a, f32::MAX);
440
            for other in ALL_AXES.iter().filter(|o| **o != a) {
441
                assert_eq!(s.axis(*other).to_bits(), 0.0f32.to_bits());
442
            }
443
        }
444
    }
445

            
446
    /// Boundary + out-of-range: the doc gives sticks `[-1, 1]` and triggers
447
    /// `[0, 1]`, but `axis()` is a plain accessor — range enforcement is the
448
    /// *backend's* contract, not this getter's. Pin the pass-through so nobody
449
    /// "helpfully" adds a silent clamp that would hide a mis-scaling backend.
450
    #[test]
451
    fn axis_does_not_clamp_out_of_range_values() {
452
        for a in ALL_AXES {
453
            for v in [-1.0f32, 0.0, 1.0, 1.000_001, -1.000_001, 1e9, -1e9] {
454
                let mut s = GamepadState::empty(GamepadId { id: 0 });
455
                set_axis(&mut s, a, v);
456
                assert_eq!(
457
                    s.axis(a).to_bits(),
458
                    v.to_bits(),
459
                    "axis {a:?} clamped or rounded {v}"
460
                );
461
            }
462
        }
463
    }
464

            
465
    /// `axis()` is `const fn`.
466
    #[test]
467
    fn axis_is_const_evaluable() {
468
        const S: GamepadState = GamepadState {
469
            id: GamepadId { id: 0 },
470
            connected: true,
471
            buttons: 0,
472
            left_stick_x: 0.0,
473
            left_stick_y: 0.0,
474
            right_stick_x: 0.0,
475
            right_stick_y: 0.0,
476
            left_z: 1.0,
477
            right_z: 0.0,
478
            // Listed explicitly: this is a `const`, and
479
            // `Default::default()` is not a const fn.
480
            battery: -1.0,
481
            touchpad_x: 0.0,
482
            touchpad_y: 0.0,
483
            touchpad2_x: 0.0,
484
            touchpad2_y: 0.0,
485
            touchpad_active: false,
486
            touchpad2_active: false,
487
            gyro_x: 0.0,
488
            gyro_y: 0.0,
489
            gyro_z: 0.0,
490
            accel_x: 0.0,
491
            accel_y: 0.0,
492
            accel_z: 0.0,
493
        };
494
        const LEFT_Z: f32 = S.axis(GamepadAxis::LeftZ);
495
        const RIGHT_Z: f32 = S.axis(GamepadAxis::RightZ);
496
        assert_eq!(LEFT_Z.to_bits(), 1.0f32.to_bits());
497
        assert_eq!(RIGHT_Z.to_bits(), 0.0f32.to_bits());
498
    }
499

            
500
    // ------------------------------------------------------------------
501
    // GamepadState / OptionGamepadState — derived-impl invariants
502
    // ------------------------------------------------------------------
503

            
504
    /// FFI trap, asserted rather than fixed: `GamepadState` derives
505
    /// `PartialEq` over `f32`, so IEEE-754 applies — a snapshot with a NaN axis
506
    /// is *not equal to itself*. Callers that dedupe frames with `==` (e.g.
507
    /// "skip the callback if the state didn't change") will therefore always
508
    /// see a change once a backend reports a NaN axis. Reflexivity holds for
509
    /// every non-NaN state.
510
    #[test]
511
    fn state_equality_is_ieee_not_reflexive_over_nan() {
512
        let mut nan_state = GamepadState::empty(GamepadId { id: 0 });
513
        nan_state.left_stick_x = f32::NAN;
514
        let a = nan_state;
515
        let b = nan_state; // a bit-identical copy
516
        assert_ne!(
517
            a, b,
518
            "NaN axis: derived PartialEq is expected to be non-reflexive"
519
        );
520

            
521
        let mut sane = GamepadState::empty(GamepadId { id: 0 });
522
        sane.left_stick_x = 0.5;
523
        let c = sane;
524
        let d = sane;
525
        assert_eq!(c, d);
526
    }
527

            
528
    /// round-trip: `GamepadState` -> `Option` -> `OptionGamepadState` -> back.
529
    /// This is the wrapper `CallbackInfo::get_gamepad_state` returns across the
530
    /// FFI, so encode == decode must hold in both directions, and the default
531
    /// must be the "no such pad" case.
532
    #[test]
533
    fn option_gamepad_state_roundtrips() {
534
        assert!(OptionGamepadState::default().is_none());
535
        assert!(!OptionGamepadState::default().is_some());
536
        assert_eq!(
537
            Option::<GamepadState>::from(OptionGamepadState::default()),
538
            None
539
        );
540

            
541
        let mut s = GamepadState::empty(GamepadId { id: u32::MAX });
542
        s.connected = true;
543
        s.buttons = ALL_BUTTONS_MASK;
544
        s.right_stick_y = -1.0;
545
        s.left_z = 1.0;
546

            
547
        let wrapped: OptionGamepadState = Some(s).into();
548
        assert!(wrapped.is_some());
549
        assert!(!wrapped.is_none());
550
        assert_eq!(wrapped.as_option(), Some(&s));
551
        assert_eq!(Option::<GamepadState>::from(wrapped), Some(s));
552

            
553
        let none: OptionGamepadState = Option::<GamepadState>::None.into();
554
        assert!(none.is_none());
555

            
556
        // `replace` returns the PREVIOUS value (mem::replace semantics).
557
        let mut slot = OptionGamepadState::None;
558
        let prev = slot.replace(s);
559
        assert!(prev.is_none());
560
        assert_eq!(slot.as_option(), Some(&s));
561

            
562
        let other = GamepadState::empty(GamepadId { id: 1 });
563
        let prev = slot.replace(other);
564
        assert_eq!(Option::<GamepadState>::from(prev), Some(s));
565
        assert_eq!(slot.as_option(), Some(&other));
566
    }
567
}