diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index 3318347946..1a2734df0c 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -47,23 +47,23 @@ pub struct Gamepads { impl Gamepads { /// Returns `true` if the `gamepad` is connected. - pub fn contains(&self, gamepad: &Gamepad) -> bool { - self.gamepads.contains(gamepad) + pub fn contains(&self, gamepad: Gamepad) -> bool { + self.gamepads.contains(&gamepad) } - /// An iterator visiting all connected [`Gamepad`]s in arbitrary order. - pub fn iter(&self) -> impl Iterator + '_ { - self.gamepads.iter() + /// Returns an iterator over registered [`Gamepad`]s in an arbitrary order. + pub fn iter(&self) -> impl Iterator + '_ { + self.gamepads.iter().copied() } - /// Registers the `gamepad` marking it as connected. + /// Registers the `gamepad`, marking it as connected. fn register(&mut self, gamepad: Gamepad) { self.gamepads.insert(gamepad); } - /// Deregisters the `gamepad` marking it as disconnected. - fn deregister(&mut self, gamepad: &Gamepad) { - self.gamepads.remove(gamepad); + /// Deregisters the `gamepad`, marking it as disconnected. + fn deregister(&mut self, gamepad: Gamepad) { + self.gamepads.remove(&gamepad); } } @@ -154,7 +154,7 @@ impl GamepadEvent { /// button_inputs: ResMut>, /// ) { /// let gamepad = gamepads.iter().next().unwrap(); -/// let gamepad_button= GamepadButton::new(*gamepad, GamepadButtonType::South); +/// let gamepad_button= GamepadButton::new(gamepad, GamepadButtonType::South); /// /// my_resource.0 = button_inputs.pressed(gamepad_button); /// } @@ -673,7 +673,7 @@ pub fn gamepad_connection_system( info!("{:?} Connected", event.gamepad); } GamepadEventType::Disconnected => { - gamepads.deregister(&event.gamepad); + gamepads.deregister(event.gamepad); info!("{:?} Disconnected", event.gamepad); } _ => (), diff --git a/examples/input/gamepad_input.rs b/examples/input/gamepad_input.rs index 9ad04ff2c8..10adf077e7 100644 --- a/examples/input/gamepad_input.rs +++ b/examples/input/gamepad_input.rs @@ -15,7 +15,7 @@ fn gamepad_system( button_axes: Res>, axes: Res>, ) { - for gamepad in gamepads.iter().cloned() { + for gamepad in gamepads.iter() { if button_inputs.just_pressed(GamepadButton::new(gamepad, GamepadButtonType::South)) { info!("{:?} just pressed South", gamepad); } else if button_inputs.just_released(GamepadButton::new(gamepad, GamepadButtonType::South))