boxdd 0.4.0

Safe, ergonomic Rust bindings for Box2D v3
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
use std::marker::PhantomData;
use std::os::raw::c_void;
use std::sync::Arc;

use crate::core::world_core::WorldCore;
use crate::error::ApiResult;
use crate::query::Aabb;
use crate::types::{BodyId, ContactData, JointId, MassData, ShapeId, Vec2};
use crate::world::World;
use boxdd_sys::ffi;

use super::definition::BodyType;
use super::runtime::BodyRuntimeHandle;

/// A body handle with lifetime tied to the owning world.
pub struct Body<'w> {
    pub(crate) id: BodyId,
    pub(crate) core: Arc<WorldCore>,
    _world: PhantomData<&'w World>,
}

impl<'w> Body<'w> {
    pub(crate) fn new(core: Arc<WorldCore>, id: BodyId) -> Self {
        Self {
            id,
            core,
            _world: PhantomData,
        }
    }

    pub fn id(&self) -> BodyId {
        self.id
    }

    pub fn world_id_raw(&self) -> ffi::b2WorldId {
        BodyRuntimeHandle::world_id_raw(self)
    }

    pub fn try_world_id_raw(&self) -> ApiResult<ffi::b2WorldId> {
        BodyRuntimeHandle::try_world_id_raw(self)
    }

    pub fn is_valid(&self) -> bool {
        BodyRuntimeHandle::is_valid(self)
    }

    pub fn try_is_valid(&self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_is_valid(self)
    }

    // Queries
    pub fn position(&self) -> Vec2 {
        BodyRuntimeHandle::position(self)
    }

    pub fn try_position(&self) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_position(self)
    }

    pub fn linear_velocity(&self) -> Vec2 {
        BodyRuntimeHandle::linear_velocity(self)
    }

    pub fn try_linear_velocity(&self) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_linear_velocity(self)
    }

    pub fn angular_velocity(&self) -> f32 {
        BodyRuntimeHandle::angular_velocity(self)
    }

    pub fn try_angular_velocity(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_angular_velocity(self)
    }

    pub fn rotation(&self) -> crate::Rot {
        BodyRuntimeHandle::rotation(self)
    }

    pub fn try_rotation(&self) -> ApiResult<crate::Rot> {
        BodyRuntimeHandle::try_rotation(self)
    }

    pub fn rotation_raw(&self) -> ffi::b2Rot {
        BodyRuntimeHandle::rotation_raw(self)
    }

    pub fn try_rotation_raw(&self) -> ApiResult<ffi::b2Rot> {
        BodyRuntimeHandle::try_rotation_raw(self)
    }

    pub fn transform(&self) -> crate::Transform {
        BodyRuntimeHandle::transform(self)
    }

    pub fn try_transform(&self) -> ApiResult<crate::Transform> {
        BodyRuntimeHandle::try_transform(self)
    }

    pub fn transform_raw(&self) -> ffi::b2Transform {
        BodyRuntimeHandle::transform_raw(self)
    }

    pub fn try_transform_raw(&self) -> ApiResult<ffi::b2Transform> {
        BodyRuntimeHandle::try_transform_raw(self)
    }

    pub fn aabb(&self) -> Aabb {
        BodyRuntimeHandle::aabb(self)
    }

    pub fn try_aabb(&self) -> ApiResult<Aabb> {
        BodyRuntimeHandle::try_aabb(self)
    }

    pub fn local_point<V: Into<Vec2>>(&self, world_point: V) -> Vec2 {
        BodyRuntimeHandle::local_point(self, world_point)
    }

    pub fn try_local_point<V: Into<Vec2>>(&self, world_point: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_local_point(self, world_point)
    }

    pub fn world_point<V: Into<Vec2>>(&self, local_point: V) -> Vec2 {
        BodyRuntimeHandle::world_point(self, local_point)
    }

    pub fn try_world_point<V: Into<Vec2>>(&self, local_point: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_world_point(self, local_point)
    }

    pub fn local_vector<V: Into<Vec2>>(&self, world_vector: V) -> Vec2 {
        BodyRuntimeHandle::local_vector(self, world_vector)
    }

    pub fn try_local_vector<V: Into<Vec2>>(&self, world_vector: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_local_vector(self, world_vector)
    }

    pub fn world_vector<V: Into<Vec2>>(&self, local_vector: V) -> Vec2 {
        BodyRuntimeHandle::world_vector(self, local_vector)
    }

    pub fn try_world_vector<V: Into<Vec2>>(&self, local_vector: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_world_vector(self, local_vector)
    }

    pub fn local_point_velocity<V: Into<Vec2>>(&self, local_point: V) -> Vec2 {
        BodyRuntimeHandle::local_point_velocity(self, local_point)
    }

    pub fn try_local_point_velocity<V: Into<Vec2>>(&self, local_point: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_local_point_velocity(self, local_point)
    }

    pub fn world_point_velocity<V: Into<Vec2>>(&self, world_point: V) -> Vec2 {
        BodyRuntimeHandle::world_point_velocity(self, world_point)
    }

    pub fn try_world_point_velocity<V: Into<Vec2>>(&self, world_point: V) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_world_point_velocity(self, world_point)
    }

    // Mutations
    pub fn set_position_and_rotation<V: Into<Vec2>>(&mut self, p: V, angle_radians: f32) {
        BodyRuntimeHandle::set_position_and_rotation(self, p, angle_radians);
    }
    pub fn set_linear_velocity<V: Into<Vec2>>(&mut self, v: V) {
        BodyRuntimeHandle::set_linear_velocity(self, v)
    }

    pub fn try_set_linear_velocity<V: Into<Vec2>>(&mut self, v: V) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_linear_velocity(self, v)
    }

    pub fn set_angular_velocity(&mut self, w: f32) {
        BodyRuntimeHandle::set_angular_velocity(self, w)
    }

    pub fn try_set_angular_velocity(&mut self, w: f32) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_angular_velocity(self, w)
    }

    pub fn set_target_transform(&mut self, target: crate::Transform, time_step: f32, wake: bool) {
        BodyRuntimeHandle::set_target_transform(self, target, time_step, wake);
    }

    pub fn try_set_target_transform(
        &mut self,
        target: crate::Transform,
        time_step: f32,
        wake: bool,
    ) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_target_transform(self, target, time_step, wake)
    }

    pub fn contact_data(&self) -> Vec<ContactData> {
        BodyRuntimeHandle::contact_data(self)
    }

    pub fn contact_data_into(&self, out: &mut Vec<ContactData>) {
        BodyRuntimeHandle::contact_data_into(self, out);
    }

    pub fn try_contact_data(&self) -> ApiResult<Vec<ContactData>> {
        BodyRuntimeHandle::try_contact_data(self)
    }

    pub fn try_contact_data_into(&self, out: &mut Vec<ContactData>) -> ApiResult<()> {
        BodyRuntimeHandle::try_contact_data_into(self, out)
    }

    pub fn contact_data_raw(&self) -> Vec<ffi::b2ContactData> {
        BodyRuntimeHandle::contact_data_raw(self)
    }

    pub fn contact_data_raw_into(&self, out: &mut Vec<ffi::b2ContactData>) {
        BodyRuntimeHandle::contact_data_raw_into(self, out);
    }

    pub fn try_contact_data_raw(&self) -> ApiResult<Vec<ffi::b2ContactData>> {
        BodyRuntimeHandle::try_contact_data_raw(self)
    }

    pub fn try_contact_data_raw_into(&self, out: &mut Vec<ffi::b2ContactData>) -> ApiResult<()> {
        BodyRuntimeHandle::try_contact_data_raw_into(self, out)
    }

    // Forces/impulses
    pub fn apply_force<F: Into<Vec2>, P: Into<Vec2>>(&mut self, force: F, point: P, wake: bool) {
        BodyRuntimeHandle::apply_force(self, force, point, wake);
    }

    pub fn try_apply_force<F: Into<Vec2>, P: Into<Vec2>>(
        &mut self,
        force: F,
        point: P,
        wake: bool,
    ) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_force(self, force, point, wake)
    }
    pub fn apply_force_to_center<V: Into<Vec2>>(&mut self, force: V, wake: bool) {
        BodyRuntimeHandle::apply_force_to_center(self, force, wake);
    }

    pub fn try_apply_force_to_center<V: Into<Vec2>>(
        &mut self,
        force: V,
        wake: bool,
    ) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_force_to_center(self, force, wake)
    }
    pub fn apply_torque(&mut self, torque: f32, wake: bool) {
        BodyRuntimeHandle::apply_torque(self, torque, wake)
    }

    pub fn try_apply_torque(&mut self, torque: f32, wake: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_torque(self, torque, wake)
    }

    pub fn clear_forces(&mut self) {
        BodyRuntimeHandle::clear_forces(self);
    }

    pub fn try_clear_forces(&mut self) -> ApiResult<()> {
        BodyRuntimeHandle::try_clear_forces(self)
    }

    pub fn apply_linear_impulse<F: Into<Vec2>, P: Into<Vec2>>(
        &mut self,
        impulse: F,
        point: P,
        wake: bool,
    ) {
        BodyRuntimeHandle::apply_linear_impulse(self, impulse, point, wake);
    }

    pub fn try_apply_linear_impulse<F: Into<Vec2>, P: Into<Vec2>>(
        &mut self,
        impulse: F,
        point: P,
        wake: bool,
    ) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_linear_impulse(self, impulse, point, wake)
    }
    pub fn apply_linear_impulse_to_center<V: Into<Vec2>>(&mut self, impulse: V, wake: bool) {
        BodyRuntimeHandle::apply_linear_impulse_to_center(self, impulse, wake);
    }

    pub fn try_apply_linear_impulse_to_center<V: Into<Vec2>>(
        &mut self,
        impulse: V,
        wake: bool,
    ) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_linear_impulse_to_center(self, impulse, wake)
    }
    pub fn apply_angular_impulse(&mut self, impulse: f32, wake: bool) {
        BodyRuntimeHandle::apply_angular_impulse(self, impulse, wake)
    }

    pub fn try_apply_angular_impulse(&mut self, impulse: f32, wake: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_angular_impulse(self, impulse, wake)
    }

    pub fn mass(&self) -> f32 {
        BodyRuntimeHandle::mass(self)
    }

    pub fn try_mass(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_mass(self)
    }

    pub fn rotational_inertia(&self) -> f32 {
        BodyRuntimeHandle::rotational_inertia(self)
    }

    pub fn try_rotational_inertia(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_rotational_inertia(self)
    }

    pub fn local_center_of_mass(&self) -> Vec2 {
        BodyRuntimeHandle::local_center_of_mass(self)
    }

    pub fn try_local_center_of_mass(&self) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_local_center_of_mass(self)
    }

    pub fn world_center_of_mass(&self) -> Vec2 {
        BodyRuntimeHandle::world_center_of_mass(self)
    }

    pub fn try_world_center_of_mass(&self) -> ApiResult<Vec2> {
        BodyRuntimeHandle::try_world_center_of_mass(self)
    }

    pub fn mass_data(&self) -> MassData {
        BodyRuntimeHandle::mass_data(self)
    }

    pub fn try_mass_data(&self) -> ApiResult<MassData> {
        BodyRuntimeHandle::try_mass_data(self)
    }

    pub fn set_mass_data(&mut self, mass_data: MassData) {
        BodyRuntimeHandle::set_mass_data(self, mass_data);
    }

    pub fn try_set_mass_data(&mut self, mass_data: MassData) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_mass_data(self, mass_data)
    }

    pub fn apply_mass_from_shapes(&mut self) {
        BodyRuntimeHandle::apply_mass_from_shapes(self);
    }

    pub fn try_apply_mass_from_shapes(&mut self) -> ApiResult<()> {
        BodyRuntimeHandle::try_apply_mass_from_shapes(self)
    }

    pub fn shape_count(&self) -> i32 {
        BodyRuntimeHandle::shape_count(self)
    }

    pub fn try_shape_count(&self) -> ApiResult<i32> {
        BodyRuntimeHandle::try_shape_count(self)
    }

    pub fn shapes(&self) -> Vec<ShapeId> {
        BodyRuntimeHandle::shapes(self)
    }

    pub fn shapes_into(&self, out: &mut Vec<ShapeId>) {
        BodyRuntimeHandle::shapes_into(self, out);
    }

    pub fn try_shapes(&self) -> ApiResult<Vec<ShapeId>> {
        BodyRuntimeHandle::try_shapes(self)
    }

    pub fn try_shapes_into(&self, out: &mut Vec<ShapeId>) -> ApiResult<()> {
        BodyRuntimeHandle::try_shapes_into(self, out)
    }

    pub fn joint_count(&self) -> i32 {
        BodyRuntimeHandle::joint_count(self)
    }

    pub fn try_joint_count(&self) -> ApiResult<i32> {
        BodyRuntimeHandle::try_joint_count(self)
    }

    pub fn joints(&self) -> Vec<JointId> {
        BodyRuntimeHandle::joints(self)
    }

    pub fn joints_into(&self, out: &mut Vec<JointId>) {
        BodyRuntimeHandle::joints_into(self, out);
    }

    pub fn try_joints(&self) -> ApiResult<Vec<JointId>> {
        BodyRuntimeHandle::try_joints(self)
    }

    pub fn try_joints_into(&self, out: &mut Vec<JointId>) -> ApiResult<()> {
        BodyRuntimeHandle::try_joints_into(self, out)
    }

    pub fn body_type(&self) -> BodyType {
        BodyRuntimeHandle::body_type(self)
    }

    pub fn try_body_type(&self) -> ApiResult<BodyType> {
        BodyRuntimeHandle::try_body_type(self)
    }
    pub fn set_body_type(&mut self, t: BodyType) {
        BodyRuntimeHandle::set_body_type(self, t)
    }

    pub fn try_set_body_type(&mut self, t: BodyType) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_body_type(self, t)
    }

    pub fn gravity_scale(&self) -> f32 {
        BodyRuntimeHandle::gravity_scale(self)
    }
    pub fn try_gravity_scale(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_gravity_scale(self)
    }
    pub fn set_gravity_scale(&mut self, v: f32) {
        BodyRuntimeHandle::set_gravity_scale(self, v)
    }

    pub fn try_set_gravity_scale(&mut self, v: f32) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_gravity_scale(self, v)
    }

    pub fn linear_damping(&self) -> f32 {
        BodyRuntimeHandle::linear_damping(self)
    }
    pub fn try_linear_damping(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_linear_damping(self)
    }
    pub fn set_linear_damping(&mut self, v: f32) {
        BodyRuntimeHandle::set_linear_damping(self, v)
    }
    pub fn try_set_linear_damping(&mut self, v: f32) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_linear_damping(self, v)
    }
    pub fn angular_damping(&self) -> f32 {
        BodyRuntimeHandle::angular_damping(self)
    }
    pub fn try_angular_damping(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_angular_damping(self)
    }
    pub fn set_angular_damping(&mut self, v: f32) {
        BodyRuntimeHandle::set_angular_damping(self, v)
    }

    pub fn try_set_angular_damping(&mut self, v: f32) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_angular_damping(self, v)
    }

    pub fn enable_sleep(&mut self, flag: bool) {
        BodyRuntimeHandle::enable_sleep(self, flag)
    }

    pub fn try_enable_sleep(&mut self, flag: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_enable_sleep(self, flag)
    }

    pub fn is_sleep_enabled(&self) -> bool {
        BodyRuntimeHandle::is_sleep_enabled(self)
    }

    pub fn try_is_sleep_enabled(&self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_is_sleep_enabled(self)
    }

    pub fn set_sleep_threshold(&mut self, sleep_threshold: f32) {
        BodyRuntimeHandle::set_sleep_threshold(self, sleep_threshold)
    }

    pub fn try_set_sleep_threshold(&mut self, sleep_threshold: f32) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_sleep_threshold(self, sleep_threshold)
    }

    pub fn sleep_threshold(&self) -> f32 {
        BodyRuntimeHandle::sleep_threshold(self)
    }

    pub fn try_sleep_threshold(&self) -> ApiResult<f32> {
        BodyRuntimeHandle::try_sleep_threshold(self)
    }

    pub fn is_awake(&self) -> bool {
        BodyRuntimeHandle::is_awake(self)
    }
    pub fn set_awake(&mut self, awake: bool) {
        BodyRuntimeHandle::set_awake(self, awake)
    }

    pub fn try_is_awake(&self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_is_awake(self)
    }

    pub fn try_set_awake(&mut self, awake: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_awake(self, awake)
    }

    pub fn is_enabled(&self) -> bool {
        BodyRuntimeHandle::is_enabled(self)
    }
    pub fn enable(&mut self) {
        BodyRuntimeHandle::enable(self)
    }
    pub fn disable(&mut self) {
        BodyRuntimeHandle::disable(self)
    }

    pub fn try_is_enabled(&self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_is_enabled(self)
    }

    pub fn try_enable(&mut self) -> ApiResult<()> {
        BodyRuntimeHandle::try_enable(self)
    }

    pub fn try_disable(&mut self) -> ApiResult<()> {
        BodyRuntimeHandle::try_disable(self)
    }

    pub fn is_bullet(&self) -> bool {
        BodyRuntimeHandle::is_bullet(self)
    }
    pub fn set_bullet(&mut self, flag: bool) {
        BodyRuntimeHandle::set_bullet(self, flag)
    }

    pub fn try_is_bullet(&self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_is_bullet(self)
    }

    pub fn try_set_bullet(&mut self, flag: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_bullet(self, flag)
    }

    pub fn enable_contact_events(&mut self, flag: bool) {
        BodyRuntimeHandle::enable_contact_events(self, flag)
    }

    pub fn try_enable_contact_events(&mut self, flag: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_enable_contact_events(self, flag)
    }

    pub fn enable_hit_events(&mut self, flag: bool) {
        BodyRuntimeHandle::enable_hit_events(self, flag)
    }

    pub fn try_enable_hit_events(&mut self, flag: bool) -> ApiResult<()> {
        BodyRuntimeHandle::try_enable_hit_events(self, flag)
    }

    // Names and user data (raw pointer)
    pub fn set_name(&mut self, name: &str) {
        BodyRuntimeHandle::set_name(self, name)
    }

    pub fn try_set_name(&mut self, name: &str) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_name(self, name)
    }

    pub fn name(&self) -> Option<String> {
        BodyRuntimeHandle::name(self)
    }

    pub fn try_name(&self) -> ApiResult<Option<String>> {
        BodyRuntimeHandle::try_name(self)
    }
    /// Set an opaque user data pointer on this body.
    ///
    /// # Safety
    /// The caller must ensure that `p` is either null or points to a valid object
    /// for the entire time the body may access it, and that any lifetimes/aliasing rules
    /// are upheld. Box2D treats this as an opaque pointer and may store/use it across steps.
    ///
    /// If typed user data was previously set via `set_user_data`, it will be cleared and dropped.
    pub unsafe fn set_user_data_ptr_raw(&mut self, p: *mut c_void) {
        unsafe { BodyRuntimeHandle::set_user_data_ptr_raw(self, p) }
    }

    /// Set an opaque user data pointer on this body.
    ///
    /// # Safety
    /// Same safety contract as `set_user_data_ptr_raw`.
    ///
    /// If typed user data was previously set via `set_user_data`, it will be cleared and dropped.
    pub unsafe fn try_set_user_data_ptr_raw(&mut self, p: *mut c_void) -> ApiResult<()> {
        unsafe { BodyRuntimeHandle::try_set_user_data_ptr_raw(self, p) }
    }
    pub fn user_data_ptr_raw(&self) -> *mut c_void {
        BodyRuntimeHandle::user_data_ptr_raw(self)
    }

    pub fn try_user_data_ptr_raw(&self) -> ApiResult<*mut c_void> {
        BodyRuntimeHandle::try_user_data_ptr_raw(self)
    }

    /// Set typed user data on this body.
    ///
    /// This stores a `Box<T>` internally and sets Box2D's user data pointer to it. The allocation
    /// is automatically freed when cleared or when the body is destroyed.
    pub fn set_user_data<T: 'static>(&mut self, value: T) {
        BodyRuntimeHandle::set_user_data(self, value);
    }

    pub fn try_set_user_data<T: 'static>(&mut self, value: T) -> ApiResult<()> {
        BodyRuntimeHandle::try_set_user_data(self, value)
    }

    /// Clear typed user data on this body. Returns whether any typed data was present.
    pub fn clear_user_data(&mut self) -> bool {
        BodyRuntimeHandle::clear_user_data(self)
    }

    pub fn try_clear_user_data(&mut self) -> ApiResult<bool> {
        BodyRuntimeHandle::try_clear_user_data(self)
    }

    pub fn with_user_data<T: 'static, R>(&self, f: impl FnOnce(&T) -> R) -> Option<R> {
        BodyRuntimeHandle::with_user_data(self, f)
    }

    pub fn try_with_user_data<T: 'static, R>(
        &self,
        f: impl FnOnce(&T) -> R,
    ) -> ApiResult<Option<R>> {
        BodyRuntimeHandle::try_with_user_data(self, f)
    }

    pub fn with_user_data_mut<T: 'static, R>(&mut self, f: impl FnOnce(&mut T) -> R) -> Option<R> {
        BodyRuntimeHandle::with_user_data_mut(self, f)
    }

    pub fn try_with_user_data_mut<T: 'static, R>(
        &mut self,
        f: impl FnOnce(&mut T) -> R,
    ) -> ApiResult<Option<R>> {
        BodyRuntimeHandle::try_with_user_data_mut(self, f)
    }

    pub fn take_user_data<T: 'static>(&mut self) -> Option<T> {
        BodyRuntimeHandle::take_user_data(self)
    }

    pub fn try_take_user_data<T: 'static>(&mut self) -> ApiResult<Option<T>> {
        BodyRuntimeHandle::try_take_user_data(self)
    }

    /// Borrow the raw id for ID-style APIs.
    pub fn as_id(&self) -> BodyId {
        self.id
    }
}