diff --git a/Cargo.toml b/Cargo.toml index 9de36d99..3fcd3077 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ include = ["/src", "/tests", "/examples", "/LICENSE*"] bevy_enhanced_input_macros = { path = "macros", version = "0.7.0" } bevy = { version = "0.15", default-features = false, features = ["serialize"] } bevy_egui = { version = "0.33", default-features = false, optional = true } -serde = "1.0" +serde = { version = "1.0", default-features = false, features = ["derive"] } bitflags = { version = "2.6", features = ["serde"] } [dev-dependencies] @@ -48,6 +48,9 @@ required-features = [ [lints.clippy] type_complexity = "allow" +alloc_instead_of_core = "warn" +std_instead_of_alloc = "warn" +std_instead_of_core = "warn" [workspace] members = ["macros"] diff --git a/examples/context_layering.rs b/examples/context_layering.rs index 1344e600..508bd121 100644 --- a/examples/context_layering.rs +++ b/examples/context_layering.rs @@ -2,7 +2,7 @@ mod player_box; -use std::f32::consts::FRAC_PI_4; +use core::f32::consts::FRAC_PI_4; use bevy::{color::palettes::tailwind::INDIGO_600, prelude::*}; use bevy_enhanced_input::prelude::*; diff --git a/examples/context_switch.rs b/examples/context_switch.rs index 4e2df0a5..fa4e3c29 100644 --- a/examples/context_switch.rs +++ b/examples/context_switch.rs @@ -2,7 +2,7 @@ mod player_box; -use std::f32::consts::FRAC_PI_4; +use core::f32::consts::FRAC_PI_4; use bevy::{color::palettes::tailwind::FUCHSIA_400, prelude::*}; use bevy_enhanced_input::prelude::*; diff --git a/examples/keybinding_menu.rs b/examples/keybinding_menu.rs index 98a798de..e6a67417 100644 --- a/examples/keybinding_menu.rs +++ b/examples/keybinding_menu.rs @@ -1,4 +1,5 @@ -use std::{error::Error, fmt::Write, fs}; +use core::{error::Error, fmt::Write}; +use std::fs; use bevy::{ input::{common_conditions::*, keyboard::KeyboardInput, mouse::MouseButtonInput, ButtonState}, diff --git a/examples/local_multiplayer.rs b/examples/local_multiplayer.rs index e5ce99f3..51bced98 100644 --- a/examples/local_multiplayer.rs +++ b/examples/local_multiplayer.rs @@ -2,7 +2,7 @@ mod player_box; -use std::f32::consts::FRAC_PI_4; +use core::f32::consts::FRAC_PI_4; use bevy::{ color::palettes::tailwind::{BLUE_600, RED_600}, diff --git a/examples/simple.rs b/examples/simple.rs index 20b6b3e8..d4cdceb9 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -2,7 +2,7 @@ mod player_box; -use std::f32::consts::FRAC_PI_4; +use core::f32::consts::FRAC_PI_4; use bevy::prelude::*; use bevy_enhanced_input::prelude::*; diff --git a/src/action_value.rs b/src/action_value.rs index 6809214e..210af981 100644 --- a/src/action_value.rs +++ b/src/action_value.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use core::fmt::Debug; use bevy::prelude::*; use serde::{Deserialize, Serialize}; diff --git a/src/events.rs b/src/events.rs index 4f172dca..6330fa91 100644 --- a/src/events.rs +++ b/src/events.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use core::fmt::Debug; use bevy::prelude::*; use bitflags::bitflags; diff --git a/src/input.rs b/src/input.rs index 83e3ff4d..eec101a9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,4 +1,4 @@ -use std::{ +use core::{ fmt::{self, Display, Formatter}, hash::Hash, }; @@ -265,6 +265,8 @@ impl From for GamepadDevice { #[cfg(test)] mod tests { + use alloc::string::ToString; + use super::*; #[test] diff --git a/src/input_action.rs b/src/input_action.rs index 368dabb1..f2784e80 100644 --- a/src/input_action.rs +++ b/src/input_action.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use core::fmt::Debug; use bevy::prelude::*; diff --git a/src/input_bind.rs b/src/input_bind.rs index 9278e90f..175af763 100644 --- a/src/input_bind.rs +++ b/src/input_bind.rs @@ -1,4 +1,5 @@ -use std::iter; +use alloc::{boxed::Box, vec::Vec}; +use core::iter; use super::{ input_condition::{InputCondition, InputConditionSet}, @@ -228,7 +229,7 @@ macro_rules! impl_tuple_binds { #[allow(non_snake_case)] fn bindings(self) -> impl Iterator { let ($($name,)+) = self; - std::iter::empty() + core::iter::empty() $(.chain($name.bindings()))+ } } diff --git a/src/input_condition.rs b/src/input_condition.rs index 74b8be95..2445d855 100644 --- a/src/input_condition.rs +++ b/src/input_condition.rs @@ -9,7 +9,8 @@ pub mod pulse; pub mod release; pub mod tap; -use std::{fmt::Debug, iter}; +use alloc::boxed::Box; +use core::{fmt::Debug, iter}; use bevy::prelude::*; @@ -97,7 +98,7 @@ macro_rules! impl_tuple_condition { #[allow(non_snake_case)] fn conditions(self) -> impl Iterator> { let ($($name,)+) = self; - std::iter::empty() + core::iter::empty() $(.chain(iter::once(Box::new($name) as Box)))+ } } diff --git a/src/input_condition/block_by.rs b/src/input_condition/block_by.rs index 5dc4ab8f..54a70481 100644 --- a/src/input_condition/block_by.rs +++ b/src/input_condition/block_by.rs @@ -1,4 +1,4 @@ -use std::{any, marker::PhantomData}; +use core::{any, marker::PhantomData}; use bevy::prelude::*; diff --git a/src/input_condition/chord.rs b/src/input_condition/chord.rs index 9cc09607..1e1d374c 100644 --- a/src/input_condition/chord.rs +++ b/src/input_condition/chord.rs @@ -1,4 +1,4 @@ -use std::{any, marker::PhantomData}; +use core::{any, marker::PhantomData}; use bevy::prelude::*; diff --git a/src/input_condition/condition_timer.rs b/src/input_condition/condition_timer.rs index d60056be..3f9df964 100644 --- a/src/input_condition/condition_timer.rs +++ b/src/input_condition/condition_timer.rs @@ -35,7 +35,7 @@ impl ConditionTimer { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; diff --git a/src/input_condition/hold.rs b/src/input_condition/hold.rs index b336fa72..7a39c3c7 100644 --- a/src/input_condition/hold.rs +++ b/src/input_condition/hold.rs @@ -92,7 +92,7 @@ impl InputCondition for Hold { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; use crate::input_context::ActionsData; diff --git a/src/input_condition/hold_and_release.rs b/src/input_condition/hold_and_release.rs index a3dad032..ec80463d 100644 --- a/src/input_condition/hold_and_release.rs +++ b/src/input_condition/hold_and_release.rs @@ -74,7 +74,7 @@ impl InputCondition for HoldAndRelease { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; use crate::input_context::ActionsData; diff --git a/src/input_condition/pulse.rs b/src/input_condition/pulse.rs index 76ccbb04..fba6e95b 100644 --- a/src/input_condition/pulse.rs +++ b/src/input_condition/pulse.rs @@ -109,7 +109,7 @@ impl InputCondition for Pulse { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; use crate::input_context::ActionsData; diff --git a/src/input_condition/tap.rs b/src/input_condition/tap.rs index 3f5bc084..12f5c5a2 100644 --- a/src/input_condition/tap.rs +++ b/src/input_condition/tap.rs @@ -79,7 +79,7 @@ impl InputCondition for Tap { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; diff --git a/src/input_context.rs b/src/input_context.rs index d815ae1e..9766b0cb 100644 --- a/src/input_context.rs +++ b/src/input_context.rs @@ -1,4 +1,5 @@ -use std::{ +use alloc::{boxed::Box, vec::Vec}; +use core::{ any::{self, TypeId}, cmp::Ordering, fmt::Debug, diff --git a/src/input_modifier.rs b/src/input_modifier.rs index a8553abf..7893430a 100644 --- a/src/input_modifier.rs +++ b/src/input_modifier.rs @@ -7,7 +7,8 @@ pub mod scale; pub mod smooth_nudge; pub mod swizzle_axis; -use std::{fmt::Debug, iter}; +use alloc::boxed::Box; +use core::{fmt::Debug, iter}; use bevy::prelude::*; @@ -56,7 +57,7 @@ macro_rules! impl_tuple_modifiers { #[allow(non_snake_case)] fn modifiers(self) -> impl Iterator> { let ($($name,)+) = self; - std::iter::empty() + core::iter::empty() $(.chain(iter::once(Box::new($name) as Box)))+ } } diff --git a/src/input_modifier/accumulate_by.rs b/src/input_modifier/accumulate_by.rs index 106a7348..ef216ff9 100644 --- a/src/input_modifier/accumulate_by.rs +++ b/src/input_modifier/accumulate_by.rs @@ -1,4 +1,4 @@ -use std::{any, marker::PhantomData}; +use core::{any, marker::PhantomData}; use bevy::prelude::*; diff --git a/src/input_modifier/delta_scale.rs b/src/input_modifier/delta_scale.rs index 09579813..4d40b728 100644 --- a/src/input_modifier/delta_scale.rs +++ b/src/input_modifier/delta_scale.rs @@ -30,7 +30,7 @@ impl InputModifier for DeltaScale { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; diff --git a/src/input_modifier/smooth_nudge.rs b/src/input_modifier/smooth_nudge.rs index 37672698..862b9344 100644 --- a/src/input_modifier/smooth_nudge.rs +++ b/src/input_modifier/smooth_nudge.rs @@ -62,7 +62,7 @@ impl InputModifier for SmoothNudge { #[cfg(test)] mod tests { - use std::time::Duration; + use core::time::Duration; use super::*; diff --git a/src/input_reader.rs b/src/input_reader.rs index 2236724f..4b77cdfd 100644 --- a/src/input_reader.rs +++ b/src/input_reader.rs @@ -1,4 +1,5 @@ -use std::hash::Hash; +use alloc::vec::Vec; +use core::hash::Hash; use bevy::{ ecs::system::SystemParam, @@ -41,7 +42,7 @@ impl InputReader<'_, '_> { self.consumed.reset(); // Temporary take the original value to avoid issues with the borrow checker. - let mut reset_input = std::mem::take(&mut *self.reset_input); + let mut reset_input = core::mem::take(&mut *self.reset_input); reset_input.retain(|&input| { if self.value(input).as_bool() { self.consume(input); diff --git a/src/lib.rs b/src/lib.rs index b64b58f2..7739c3d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,12 @@ The exact method depends on the OS shell. Alternatively you can configure [`LogPlugin`](bevy::log::LogPlugin) to make it permanent. */ +#![no_std] + +extern crate std; + +extern crate alloc; + // Required for the derive macro to work within the crate. extern crate self as bevy_enhanced_input; diff --git a/src/registry.rs b/src/registry.rs index 44c3f4b3..8e0db0c1 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -1,4 +1,5 @@ -use std::{ +use alloc::vec::Vec; +use core::{ any::{self, TypeId}, cmp::Reverse, marker::PhantomData, diff --git a/src/trigger_tracker.rs b/src/trigger_tracker.rs index b0998271..4c8d0051 100644 --- a/src/trigger_tracker.rs +++ b/src/trigger_tracker.rs @@ -1,3 +1,5 @@ +use alloc::boxed::Box; + use bevy::prelude::*; use crate::{ diff --git a/tests/condition_kind.rs b/tests/condition_kind.rs index 1079e6b3..6d886112 100644 --- a/tests/condition_kind.rs +++ b/tests/condition_kind.rs @@ -1,4 +1,4 @@ -use std::any; +use core::any; use bevy::{input::InputPlugin, prelude::*}; use bevy_enhanced_input::prelude::*; diff --git a/tests/state_and_value_merge.rs b/tests/state_and_value_merge.rs index 9707825f..ea3d3169 100644 --- a/tests/state_and_value_merge.rs +++ b/tests/state_and_value_merge.rs @@ -1,4 +1,4 @@ -use std::any; +use core::any; use bevy::{input::InputPlugin, prelude::*}; use bevy_enhanced_input::prelude::*;