Skip to content

Deny bare trait-objects #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples3d/constraints3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ extern crate ncollide3d;
extern crate nphysics3d;
extern crate nphysics_testbed3d;

use na::{Isometry3, Point3, Vector3};
use na::{Point3, Vector3};
use ncollide3d::shape::{Cuboid, ShapeHandle};
use nphysics3d::joint::{BallConstraint, PinSlotConstraint, PlanarConstraint, PrismaticConstraint,
RectangularConstraint, RevoluteConstraint, UniversalConstraint};
use nphysics3d::object::{BodyPartHandle, ColliderDesc, RigidBodyDesc};
use nphysics3d::volumetric::Volumetric;

use nphysics3d::world::World;
use nphysics_testbed3d::Testbed;
use std::f32::consts::{FRAC_PI_2, PI};
Expand Down
4 changes: 2 additions & 2 deletions examples3d/convex_decomposition3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ extern crate nphysics_testbed3d;
extern crate rand;

use std::path::Path;
use na::{Isometry3, Point3, Translation3, Vector3};
use na::{Point3, Translation3, Vector3};
use kiss3d::loader::obj;
use ncollide3d::shape::{Compound, ConvexHull, Cuboid, ShapeHandle};
use ncollide3d::procedural::TriMesh;
use ncollide3d::transformation;
use ncollide3d::bounding_volume::{self, BoundingVolume, AABB};
use ncollide3d::bounding_volume::{self, BoundingVolume};
use nphysics3d::world::World;
use nphysics3d::object::{ColliderDesc, RigidBodyDesc};
use nphysics_testbed3d::Testbed;
Expand Down
2 changes: 1 addition & 1 deletion examples3d/fem_volume3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate ncollide3d;
extern crate nphysics3d;
extern crate nphysics_testbed3d;

use na::{Point3, Vector3, Point4};
use na::{Point3, Vector3};
use ncollide3d::shape::{Cuboid, ShapeHandle};
use nphysics3d::object::{FEMVolumeDesc, ColliderDesc};
use nphysics3d::world::World;
Expand Down
6 changes: 3 additions & 3 deletions examples3d/known_bug_excentric_convex3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ extern crate ncollide3d;
extern crate nphysics3d;
extern crate nphysics_testbed3d;

use na::{Isometry3, Point3, Vector3};
use na::{Point3, Vector3};
use ncollide3d::shape::{ConvexHull, Cuboid, ShapeHandle};
use ncollide3d::procedural;

use nphysics3d::world::World;
use nphysics3d::object::{ColliderDesc, RigidBodyDesc};
use nphysics3d::volumetric::Volumetric;

use nphysics_testbed3d::Testbed;


Expand Down
6 changes: 3 additions & 3 deletions nphysics_testbed2d/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl GraphicsManager {
object: ColliderHandle,
world: &World<f32>,
delta: Isometry2<f32>,
shape: &Shape<f32>,
shape: &dyn Shape<f32>,
color: Point3<f32>,
out: &mut Vec<Node>,
) {
Expand Down Expand Up @@ -429,8 +429,8 @@ impl GraphicsManager {
// }
// }

pub fn camera_mut<'a>(&'a mut self) -> &'a mut PlanarCamera {
&mut self.camera as &'a mut PlanarCamera
pub fn camera_mut<'a>(&'a mut self) -> &'a mut dyn PlanarCamera {
&mut self.camera as &'a mut dyn PlanarCamera
}

pub fn look_at(&mut self, at: Point2<f32>, zoom: f32) {
Expand Down
18 changes: 9 additions & 9 deletions nphysics_testbed2d/src/testbed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ pub struct Testbed {
cursor_pos: Point2<f32>,
grabbed_object: Option<BodyPartHandle>,
grabbed_object_constraint: Option<ConstraintHandle>,
world: Box<WorldOwner>,
world: Box<dyn WorldOwner>,
drawing_ray: Option<Point2<f32>>,
}

type Callbacks = Vec<Box<Fn(&mut WorldOwner, &mut GraphicsManager, f32)>>;
type Callbacks = Vec<Box<dyn Fn(&mut dyn WorldOwner, &mut GraphicsManager, f32)>>;

impl Testbed {
pub fn new_empty() -> Testbed {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Testbed {
Testbed::new_with_world_owner(Box::new(world))
}

pub fn new_with_world_owner(world_owner: Box<WorldOwner>) -> Testbed {
pub fn new_with_world_owner(world_owner: Box<dyn WorldOwner>) -> Testbed {
let mut res = Testbed::new_empty();

res.set_world_owner(world_owner);
Expand All @@ -154,7 +154,7 @@ impl Testbed {
self.set_world_owner(Box::new(world));
}

pub fn set_world_owner(&mut self, world: Box<WorldOwner>) {
pub fn set_world_owner(&mut self, world: Box<dyn WorldOwner>) {
self.world = world;
let mut world = self.world.get_mut();
world.enable_performance_counters();
Expand All @@ -179,7 +179,7 @@ impl Testbed {
self.graphics.set_collider_color(collider, color);
}

pub fn world(&self) -> &Box<WorldOwner> {
pub fn world(&self) -> &Box<dyn WorldOwner> {
&self.world
}

Expand Down Expand Up @@ -214,7 +214,7 @@ impl Testbed {
res
}

pub fn add_callback<F: Fn(&mut WorldOwner, &mut GraphicsManager, f32) + 'static>(
pub fn add_callback<F: Fn(&mut dyn WorldOwner, &mut GraphicsManager, f32) + 'static>(
&mut self,
callback: F,
) {
Expand Down Expand Up @@ -242,9 +242,9 @@ impl Testbed {
}

type CameraEffects<'a> = (
Option<&'a mut Camera>,
Option<&'a mut PlanarCamera>,
Option<&'a mut PostProcessingEffect>,
Option<&'a mut dyn Camera>,
Option<&'a mut dyn PlanarCamera>,
Option<&'a mut dyn PostProcessingEffect>,
);

impl State for Testbed {
Expand Down
12 changes: 6 additions & 6 deletions nphysics_testbed2d/src/world_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ use std::sync::RwLock;
pub trait WorldOwner {
// FIXME: avoid the systematic Box by using associated type
// which also requires the testbed to be parametrized by the world type.
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b>;
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b>;
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b>;
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b>;
}

impl WorldOwner for World<f32> {
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b> {
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b> {
Box::new(self)
}

fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b> {
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b> {
Box::new(self)
}
}

impl WorldOwner for Arc<RwLock<World<f32>>> {
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b> {
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b> {
Box::new(self.read().unwrap())
}

fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b> {
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b> {
Box::new(self.write().unwrap())
}
}
14 changes: 7 additions & 7 deletions nphysics_testbed3d/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl GraphicsManager {
object: ColliderHandle,
world: &World<f32>,
delta: Isometry3<f32>,
shape: &Shape<f32>,
shape: &dyn Shape<f32>,
color: Point3<f32>,
out: &mut Vec<Node>,
) {
Expand Down Expand Up @@ -443,19 +443,19 @@ impl GraphicsManager {
self.curr_is_arc_ball = !self.curr_is_arc_ball;
}

pub fn camera<'a>(&'a self) -> &'a Camera {
pub fn camera<'a>(&'a self) -> &'a dyn Camera {
if self.curr_is_arc_ball {
&self.arc_ball as &'a Camera
&self.arc_ball as &'a dyn Camera
} else {
&self.first_person as &'a Camera
&self.first_person as &'a dyn Camera
}
}

pub fn camera_mut<'a>(&'a mut self) -> &'a mut Camera {
pub fn camera_mut<'a>(&'a mut self) -> &'a mut dyn Camera {
if self.curr_is_arc_ball {
&mut self.arc_ball as &'a mut Camera
&mut self.arc_ball as &'a mut dyn Camera
} else {
&mut self.first_person as &'a mut Camera
&mut self.first_person as &'a mut dyn Camera
}
}

Expand Down
18 changes: 9 additions & 9 deletions nphysics_testbed3d/src/testbed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn usage(exe_name: &str) {
}

pub struct Testbed {
world: Box<WorldOwner>,
world: Box<dyn WorldOwner>,
window: Option<Box<Window>>,
graphics: GraphicsManager,
nsteps: usize,
Expand All @@ -99,7 +99,7 @@ pub struct Testbed {
grabbed_object_plane: (Point3<f32>, Vector3<f32>),
}

type Callbacks = Vec<Box<Fn(&mut WorldOwner, &mut GraphicsManager, f32)>>;
type Callbacks = Vec<Box<dyn Fn(&mut dyn WorldOwner, &mut GraphicsManager, f32)>>;

impl Testbed {
pub fn new_empty() -> Testbed {
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Testbed {
Self::new_with_world_owner(Box::new(world))
}

pub fn new_with_world_owner(world: Box<WorldOwner>) -> Self {
pub fn new_with_world_owner(world: Box<dyn WorldOwner>) -> Self {
let mut res = Testbed::new_empty();

res.set_world_owner(world);
Expand All @@ -157,7 +157,7 @@ impl Testbed {
self.set_world_owner(Box::new(world))
}

pub fn set_world_owner(&mut self, world: Box<WorldOwner>) {
pub fn set_world_owner(&mut self, world: Box<dyn WorldOwner>) {
self.world = world;
let mut world = self.world.get_mut();
world.enable_performance_counters();
Expand All @@ -182,7 +182,7 @@ impl Testbed {
self.graphics.set_collider_color(collider, color);
}

pub fn world(&self) -> &Box<WorldOwner> {
pub fn world(&self) -> &Box<dyn WorldOwner> {
&self.world
}

Expand Down Expand Up @@ -217,7 +217,7 @@ impl Testbed {
res
}

pub fn add_callback<F: Fn(&mut WorldOwner, &mut GraphicsManager, f32) + 'static>(
pub fn add_callback<F: Fn(&mut dyn WorldOwner, &mut GraphicsManager, f32) + 'static>(
&mut self,
callback: F,
) {
Expand Down Expand Up @@ -245,9 +245,9 @@ impl Testbed {
}

type CameraEffects<'a> = (
Option<&'a mut Camera>,
Option<&'a mut PlanarCamera>,
Option<&'a mut PostProcessingEffect>,
Option<&'a mut dyn Camera>,
Option<&'a mut dyn PlanarCamera>,
Option<&'a mut dyn PostProcessingEffect>,
);

impl State for Testbed {
Expand Down
12 changes: 6 additions & 6 deletions nphysics_testbed3d/src/world_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ use std::sync::RwLock;
pub trait WorldOwner {
// FIXME: avoid the systematic Box by using associated type
// which also requires the testbed to be parametrized by the world type.
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b>;
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b>;
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b>;
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b>;
}

impl WorldOwner for World<f32> {
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b> {
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b> {
Box::new(self)
}

fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b> {
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b> {
Box::new(self)
}
}

impl WorldOwner for Arc<RwLock<World<f32>>> {
fn get<'a: 'b, 'b>(&'a self) -> Box<Deref<Target=World<f32>> + 'b> {
fn get<'a: 'b, 'b>(&'a self) -> Box<dyn Deref<Target=World<f32>> + 'b> {
Box::new(self.read().unwrap())
}

fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target=World<f32>> + 'b> {
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<dyn DerefMut<Target=World<f32>> + 'b> {
Box::new(self.write().unwrap())
}
}
4 changes: 2 additions & 2 deletions src/detection/activation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<N: RealField> ActivationManager<N> {
self.to_activate.push(handle);
}

fn update_energy(&self, body: &mut Body<N>) {
fn update_energy(&self, body: &mut dyn Body<N>) {
// FIXME: avoid the Copy when NLL lands ?
let status = *body.activation_status();

Expand All @@ -63,7 +63,7 @@ impl<N: RealField> ActivationManager<N> {
&mut self,
bodies: &mut BodySet<N>,
cworld: &ColliderWorld<N>,
constraints: &Slab<Box<JointConstraint<N>>>,
constraints: &Slab<Box<dyn JointConstraint<N>>>,
active_bodies: &mut Vec<BodyHandle>,
) {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/joint/ball_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<N: RealField> BallJoint<N> {

impl<N: RealField> Joint<N> for BallJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/cartesian_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<N: RealField> CartesianJoint<N> {

impl<N: RealField> Joint<N> for CartesianJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/cylindrical_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<N: RealField> CylindricalJoint<N> {

impl<N: RealField> Joint<N> for CylindricalJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/fixed_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<N: RealField> FixedJoint<N> {

impl<N: RealField> Joint<N> for FixedJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/free_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<N: RealField> FreeJoint<N> {

impl<N: RealField> Joint<N> for FreeJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/helical_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<N: RealField> HelicalJoint<N> {

impl<N: RealField> Joint<N> for HelicalJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/joint/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Joint<N: RealField>: Downcast + Send + Sync {
None
}

fn clone(&self) -> Box<Joint<N>>;
fn clone(&self) -> Box<dyn Joint<N>>;
}

impl_downcast!(Joint<N> where N: RealField);
2 changes: 1 addition & 1 deletion src/joint/pin_slot_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<N: RealField> PinSlotJoint<N> {

impl<N: RealField> Joint<N> for PinSlotJoint<N> {
#[inline]
fn clone(&self) -> Box<Joint<N>> {
fn clone(&self) -> Box<dyn Joint<N>> {
Box::new(*self)
}

Expand Down
Loading