Skip to content

Commit 9f8ce98

Browse files
Refactor to minimise std usage (#668)
# Objective - Prepare for possible `no_std` support ## Solution - Added lints and switched to using `core` and `alloc` instead of `std`.
1 parent 2c3ba42 commit 9f8ce98

File tree

34 files changed

+72
-47
lines changed

34 files changed

+72
-47
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
members = ["crates/avian2d", "crates/avian3d"]
33
resolver = "2"
44

5+
[workspace.lints.clippy]
6+
alloc_instead_of_core = "warn"
7+
std_instead_of_alloc = "warn"
8+
std_instead_of_core = "warn"
9+
510
[profile.dev]
611
opt-level = 1 # Use slightly better optimization, so examples work

crates/avian2d/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ bytemuck = "1.19"
9595
criterion = { version = "0.5", features = ["html_reports"] }
9696
bevy_mod_debugdump = { version = "0.12" }
9797

98+
[lints]
99+
workspace = true
100+
98101
[package.metadata.docs.rs]
99102
# Enable features when building the docs on docs.rs
100103
features = ["diagnostic_ui"]

crates/avian2d/benches/pyramid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use core::time::Duration;
22

33
use avian2d::math::*;
44
use avian2d::prelude::*;

crates/avian2d/examples/custom_collider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl AnyCollider for CircleCollider {
123123
impl ComputeMassProperties2d for CircleCollider {
124124
fn mass(&self, density: f32) -> f32 {
125125
// In 2D, the Z length is assumed to be `1.0`, so volume == area.
126-
let volume = std::f32::consts::PI * self.radius.powi(2) as f32;
126+
let volume = core::f32::consts::PI * self.radius.powi(2) as f32;
127127
density * volume
128128
}
129129

@@ -180,7 +180,7 @@ fn setup(
180180
.with_children(|c| {
181181
// Spawn obstacles along the perimeter of the rotating body, like the teeth of a cog.
182182
let count = 8;
183-
let angle_step = std::f32::consts::TAU / count as f32;
183+
let angle_step = core::f32::consts::TAU / count as f32;
184184
for i in 0..count {
185185
let pos = Quat::from_rotation_z(i as f32 * angle_step) * Vec3::Y * center_radius;
186186
c.spawn((

crates/avian3d/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ approx = "0.5"
9999
criterion = { version = "0.5", features = ["html_reports"] }
100100
bevy_mod_debugdump = { version = "0.12" }
101101

102+
[lints]
103+
workspace = true
104+
102105
[package.metadata.docs.rs]
103106
# Enable features when building the docs on docs.rs
104107
features = ["diagnostic_ui"]

crates/avian3d/benches/cubes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use core::time::Duration;
22

33
use avian3d::math::*;
44
use avian3d::prelude::*;

crates/avian3d/examples/dynamic_character_3d/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn setup(
6464
// Environment (see the `collider_constructors` example for creating colliders from scenes)
6565
commands.spawn((
6666
SceneRoot(assets.load("character_controller_demo.glb#Scene0")),
67-
Transform::from_rotation(Quat::from_rotation_y(-std::f32::consts::PI * 0.5)),
67+
Transform::from_rotation(Quat::from_rotation_y(-core::f32::consts::PI * 0.5)),
6868
ColliderConstructorHierarchy::new(ColliderConstructor::ConvexHullFromMesh),
6969
RigidBody::Static,
7070
));

crates/avian3d/examples/kinematic_character_3d/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn setup(
6767
// Environment (see the `collider_constructors` example for creating colliders from scenes)
6868
commands.spawn((
6969
SceneRoot(assets.load("character_controller_demo.glb#Scene0")),
70-
Transform::from_rotation(Quat::from_rotation_y(-std::f32::consts::PI * 0.5)),
70+
Transform::from_rotation(Quat::from_rotation_y(-core::f32::consts::PI * 0.5)),
7171
ColliderConstructorHierarchy::new(ColliderConstructor::ConvexHullFromMesh),
7272
RigidBody::Static,
7373
));

crates/avian3d/examples/picking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! Cameras can further filter which entities are pickable with the [`PhysicsPickingFilter`] component.
88
9-
use std::f32::consts::PI;
9+
use core::f32::consts::PI;
1010

1111
use avian3d::{math::Vector, prelude::*};
1212
use bevy::{color::palettes::tailwind::*, picking::pointer::PointerInteraction, prelude::*};

crates/benches_common_2d/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ edition = "2021"
77
bevy = { version = "0.15", default-features = false }
88
avian2d = { path = "../avian2d", default-features = false }
99
criterion = "0.5"
10+
11+
[lints]
12+
workspace = true

0 commit comments

Comments
 (0)