### From and Into Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/struct.CollisionStart_search=std%3A%3Avec Provides conversions between types. ```APIDOC ## POST /from ### Description Returns the argument unchanged. This is part of the `From for T` implementation. ### Method POST ### Endpoint /from ### Parameters #### Request Body - **t** (T) - Required - The value to return. ### Response #### Success Response (200) - **T** (T) - The returned value. ## POST /into ### Description Calls `U::from(self)`. This conversion is determined by the `From for U` implementation. ### Method POST ### Endpoint /into ### Parameters #### Request Body - **self** (T) - Required - The value to convert. ### Response #### Success Response (200) - **U** (U) - The converted value. ``` -------------------------------- ### HashSet Len Method Example Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/struct.CollidingEntities This Rust code shows how to get the number of elements in a `HashSet` using the `len()` method. It starts with an empty set, inserts an element, and then asserts the length at each step. This is useful for tracking the size of the set. ```rust let mut map = HashSet::new(); assert_eq!(map.len(), 0); map.insert("foo"); assert_eq!(map.len(), 1); ``` -------------------------------- ### Slice Pointer Access Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=u32+-%3E+bool Provides methods to get mutable pointers to the start and end of a slice, and to get a reference to the underlying array if the size matches. ```APIDOC ## GET /slice/pointers ### Description Returns the two unsafe mutable pointers spanning the slice. The returned range is half-open, meaning the end pointer points one past the last element. Also provides a method to get a reference to the underlying array if the specified size `N` matches the slice length. ### Method GET ### Endpoint /slice/pointers ### Parameters #### Query Parameters - **type** (string) - Required - Specifies the type of pointer access: 'as_mut_ptr_range' or 'as_array' - **N** (usize) - Optional - The expected size of the array for 'as_array' method. ### Response #### Success Response (200) - **pointers** (*Range<*mut T>) - The mutable pointers spanning the slice (for 'as_mut_ptr_range'). - **array_ref** (&[T; N]) - A reference to the underlying array if N matches slice length (for 'as_array'). #### Response Example ```json { "pointers": { "start": "0x...", "end": "0x..." } } ``` ```json { "array_ref": [1, 2, 3] } ``` ``` ```APIDOC ## GET /slice/array/mutable ### Description Gets a mutable reference to the slice’s underlying array if the specified size `N` is exactly equal to the length of the slice. ### Method GET ### Endpoint /slice/array/mutable ### Parameters #### Query Parameters - **N** (usize) - Required - The expected size of the mutable array. ### Response #### Success Response (200) - **mutable_array_ref** (&mut [T; N]) - A mutable reference to the underlying array if N matches slice length. #### Response Example ```json { "mutable_array_ref": [1, 2, 3] } ``` ``` -------------------------------- ### CloneToUninit Implementation Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/struct.ColliderMarker_search= Documentation for the experimental `CloneToUninit` blanket implementation. ```APIDOC ## CloneToUninit Implementation ### impl CloneToUninit for T This is a nightly-only experimental API that provides a way to clone a value into uninitialized memory. #### unsafe fn clone_to_uninit(&self, dest: *mut u8) **Description**: Performs copy-assignment from `self` to `dest`. This is an `unsafe` operation. ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/avian3d/0.5.0/avian3d/data_structures/graph/enum.EdgeDirection_search=std%3A%3Avec Demonstrates the implementation of TryFrom and TryInto traits for type conversions in Rust, including error handling. ```APIDOC ## TryFrom for T ### Description Provides a fallible conversion from type `U` into type `T`. ### Method `try_from(value: U) -> Result>::Error>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **T** (type) - The successfully converted value. #### Error Response - **Error** (type) - The error type returned upon conversion failure. #### Response Example None --- ## TryInto for T ### Description Provides a fallible conversion from type `T` into type `U`. ### Method `try_into(self) -> Result>::Error>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **U** (type) - The successfully converted value. #### Error Response - **Error** (type) - The error type returned upon conversion failure. #### Response Example None ``` -------------------------------- ### Example Usage of ShapeCaster in Bevy/Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.ShapeCaster_search= Demonstrates how to spawn a ShapeCaster entity in a Bevy application and how to iterate through its detected hits. This example shows basic setup and hit processing. ```rust use avian3d::prelude::*; use bevy::prelude::*; fn setup(mut commands: Commands) { // Spawn a shape caster with a ball shape moving right starting from the origin commands.spawn(ShapeCaster::new( Collider::sphere(0.5), Vec3::ZERO, Quat::default(), Dir3::X, )); } fn print_hits(query: Query<(&ShapeCaster, &ShapeHits)>) { for (shape_caster, hits) in &query { for hit in hits.iter() { println!("Hit entity {}", hit.entity); } } } ``` -------------------------------- ### GET /slice/chunks Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=std%3A%3Avec Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. ```APIDOC ## GET /slice/chunks ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last chunk will not have length `chunk_size`. ### Method GET ### Endpoint `/slice/chunks` ### Query Parameters - **chunk_size** (usize) - Required - The desired size of each chunk. ### Response #### Success Response (200) - **iterator** (Chunks<'_, T>) - An iterator yielding slices of the original slice. #### Response Example ```json { "iterator": "..." } ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/struct.CollisionStart Provides an experimental, nightly-only API for performing copy-assignment to uninitialized memory. ```APIDOC ## POST /clone_to_uninit ### Description 🔬 This is a nightly-only experimental API. Performs copy-assignment from `self` to `dest`. ### Method POST ### Endpoint /clone_to_uninit ### Parameters #### Request Body - **self** (T) - Required - The value to copy. - **dest** (*mut u8) - Required - A mutable pointer to the destination memory location. ### Response #### Success Response (200) - **()** - Indicates successful copy-assignment. ``` -------------------------------- ### Example: Spawn Dynamic Body with Custom Gravity in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/rigid_body/struct.GravityScale_search= Demonstrates how to spawn a dynamic rigid body with a custom gravity scale using Bevy and avian3d. This example shows the practical application of the `GravityScale` struct in a Bevy ECS setup. ```Rust use avian3d::prelude::*; use bevy::prelude::*; // Spawn a dynamic body with `1.5` times the normal gravity. fn setup(mut commands: Commands) { commands.spawn((RigidBody::Dynamic, GravityScale(1.5))); } ``` -------------------------------- ### Basic Conversions Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/rigid_body/forces/struct.ConstantLocalAngularAcceleration Documentation for the `From` trait implementation. ```APIDOC ## Trait: From ### Description Provides a conversion from a type `T` to itself. ### Method - `from(t: T) -> T`: Returns the argument unchanged. ### Endpoint N/A ``` -------------------------------- ### CloneToUninit Implementation Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/solver_body/struct.SolverBodyFlags_search=u32+-%3E+bool Provides the `clone_to_uninit` method for nightly-only experimental API for copy-assignment. ```APIDOC ## impl CloneToUninit for T ### Description Provides the `clone_to_uninit` method for nightly-only experimental API for copy-assignment. ### Method `clone_to_uninit` ### Endpoint N/A (This is a trait implementation, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Slice Pointer Access Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to get mutable pointers to the start and end of a slice, useful for interacting with C-style APIs. ```APIDOC ## GET /slice/as_mut_ptr_range ### Description Returns the two unsafe mutable pointers spanning the slice. The returned range is half-open, meaning the end pointer points one past the last element. This is useful for interacting with foreign interfaces that use two pointers to refer to a range of elements. ### Method GET ### Endpoint `/slice/as_mut_ptr_range` ### Parameters None ### Request Example ```json { "example": "No request body for this operation" } ``` ### Response #### Success Response (200) - **ptr_range** (Range<*mut T>) - A range containing the start and end mutable pointers. #### Response Example ```json { "ptr_range": { "start": "0x...", "end": "0x..." } } ``` ``` -------------------------------- ### CloneToUninit Implementation Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/solver_body/struct.SolverBodyFlags_search=std%3A%3Avec Provides the `clone_to_uninit` method for nightly-only experimental API. ```APIDOC ## impl CloneToUninit for T ### Description This is a nightly-only experimental API that provides the `clone_to_uninit` method. ### Method `clone_to_uninit` ### Endpoint N/A (This is a trait implementation, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Performs copy-assignment from `self` to `dest`. #### Response Example None ``` -------------------------------- ### Hermite Interpolation Setup Source: https://docs.rs/avian3d/0.5.0/avian3d/interpolation/struct.PhysicsInterpolationPlugin_search=u32+-%3E+bool Example of how to enable Hermite interpolation for a dynamic rigid body by adding the `TransformHermiteEasing` component. ```APIDOC ## POST /websites/rs_avian3d_0_5_0_avian3d ### Description Enables Hermite interpolation for smoother translation and rotation easing by considering velocity, unlike default linear interpolation. This is achieved by adding the `TransformHermiteEasing` component to an entity. ### Method POST ### Endpoint /websites/rs_avian3d_0_5_0_avian3d ### Parameters #### Query Parameters - **enable_hermite_easing** (boolean) - Optional - Set to `true` to enable Hermite interpolation. ### Request Body ```json { "entity_id": "unique_entity_identifier", "components": [ "RigidBody::Dynamic", "Transform::default()", "TransformInterpolation", "TransformHermiteEasing" ] } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A confirmation message. #### Response Example ```json { "status": "success", "message": "Hermite interpolation enabled for entity." } ``` ``` -------------------------------- ### Type Conversion and Subscription Source: https://docs.rs/avian3d/0.5.0/avian3d/data_structures/graph/struct.EdgeWeightsMut_search= Documentation for traits related to type conversion (TryFrom, TryInto) and subscriber management (WithSubscriber). ```APIDOC ## Type Conversion and Subscription Utilities ### Description This section details traits and methods for performing fallible type conversions and managing subscriber attachments. ### Traits and Methods #### `impl TryFrom for T` - **Description**: Provides a way to attempt conversion from type `U` into type `T`, returning a `Result`. - **Type Alias**: `Error = Infallible` - The type returned in the event of a conversion error (though `Infallible` suggests errors are not expected in this specific context). - **Method**: `try_from(value: U) -> Result>::Error>` - **Description**: Performs the conversion from `value` of type `U` to type `T`. #### `impl TryInto for T` - **Description**: Provides a way to attempt conversion from type `T` into type `U`, returning a `Result`. - **Type Alias**: `Error = >::Error` - The type returned in the event of a conversion error. - **Method**: `try_into(self) -> Result>::Error>` - **Description**: Performs the conversion from `self` of type `T` to type `U`. #### `impl WithSubscriber for T` - **Description**: Allows attaching a subscriber to a type, returning a `WithDispatch` wrapper. - **Method**: `with_subscriber(self, subscriber: S) -> WithDispatch` - **Description**: Attaches the provided `Subscriber` to this type. - **Constraint**: `S` must be convertible into `Dispatch`. - **Method**: `with_current_subscriber(self) -> WithDispatch` - **Description**: Attaches the current default `Subscriber` to this type. ### Response Examples - **Success Response (200)**: `Result` for `try_from`, `Result` for `try_into`, `WithDispatch` for `with_subscriber` and `with_current_subscriber`. ``` -------------------------------- ### GET /slice/chunks_mut Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=std%3A%3Avec Returns a mutable iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices and do not overlap. ```APIDOC ## GET /slice/chunks_mut ### Description Returns a mutable iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices, and do not overlap. If `chunk_size` does not divide the length of the slice, then the last chunk will not have length `chunk_size`. ### Method GET ### Endpoint `/slice/chunks_mut` ### Query Parameters - **chunk_size** (usize) - Required - The desired size of each chunk. ### Response #### Success Response (200) - **iterator** (ChunksMut<'_, T>) - A mutable iterator yielding mutable slices of the original slice. #### Response Example ```json { "iterator": "..." } ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### Get Iterator for Slice (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.RayHits_search=u32+-%3E+bool Returns an iterator that yields references to the elements of the slice from start to end. This is a fundamental operation for processing slice elements. ```rust let slice = [10, 20, 30]; let mut iter = slice.iter(); assert_eq!(iter.next(), Some(&10)); assert_eq!(iter.next(), Some(&20)); assert_eq!(iter.next(), Some(&30)); assert_eq!(iter.next(), None); ``` -------------------------------- ### Scalar and Settings Traits Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/struct.CollisionStart Documentation for traits related to scalar types and general settings. ```APIDOC ## Trait: Scalar for T ### Description Marks a type `T` as a scalar type, typically used for primitive or simple data structures. ### Constraints - `'static` - `Clone` - `PartialEq` - `Debug` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ## Trait: Settings for T ### Description Represents a type `T` that holds configuration or settings. ### Constraints - `'static` - `Send` - `Sync` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ``` -------------------------------- ### Standard Conversions: From and Into Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/integrator/struct.IntegratorPlugin_search=u32+-%3E+bool Demonstrates the standard `From` and `Into` traits for type conversions, including identity conversion and conversions based on existing `From` implementations. ```APIDOC ## impl From for T ### Description Provides an identity conversion, returning the argument unchanged. ### Method `T::from(t: T)` ### Endpoint N/A (Trait Implementation) ## impl Into for T ### Description Converts `self` into type `U` by calling `U::from(self)`. The conversion logic is determined by the `From for U` implementation. ### Method `T::into(self) -> U` ### Endpoint N/A (Trait Implementation) ``` -------------------------------- ### GET /slice/chunks_exact Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=std%3A%3Avec Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. Elements that do not form a full chunk are omitted. ```APIDOC ## GET /slice/chunks_exact ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last up to `chunk_size-1` elements will be omitted and can be retrieved from the `remainder` function of the iterator. ### Method GET ### Endpoint `/slice/chunks_exact` ### Query Parameters - **chunk_size** (usize) - Required - The desired size of each chunk. ### Response #### Success Response (200) - **iterator** (ChunksExact<'_, T>) - An iterator yielding slices of exactly `chunk_size` elements. #### Response Example ```json { "iterator": "..." } ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/narrow_phase/struct.NarrowPhase_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for `TryFrom` and `TryInto` trait implementations, enabling fallible type conversions. ```APIDOC ## TryFrom and TryInto Implementations ### Description Provides fallible conversion between types using `TryFrom` and `TryInto` traits. ### `impl TryFrom for T` #### `type Error = Infallible` **Description:** The type returned in the event of a conversion error. #### `fn try_from(value: U) -> Result>::Error>` **Description:** Performs the conversion. **Method:** `try_from` **Endpoint:** N/A ### `impl TryInto for T` #### `type Error = >::Error` **Description:** The type returned in the event of a conversion error. #### `fn try_into(self) -> Result>::Error>` **Description:** Performs the conversion. **Method:** `try_into` **Endpoint:** N/A ``` -------------------------------- ### GET /slice/chunks_exact_mut Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=std%3A%3Avec Returns a mutable iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices and do not overlap. Elements that do not form a full chunk are omitted. ```APIDOC ## GET /slice/chunks_exact_mut ### Description Returns a mutable iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices, and do not overlap. If `chunk_size` does not divide the length of the slice, then the last up to `chunk_size-1` elements will be omitted and can be retrieved from the `into_remainder` function of the iterator. ### Method GET ### Endpoint `/slice/chunks_exact_mut` ### Query Parameters - **chunk_size** (usize) - Required - The desired size of each chunk. ### Response #### Success Response (200) - **iterator** (ChunksExactMut<'_, T>) - A mutable iterator yielding mutable slices of exactly `chunk_size` elements. #### Response Example ```json { "iterator": "..." } ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### Mutably Iterate Over Slice Elements (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.RayHits_search= Shows how to use `iter_mut()` to get a mutable iterator over slice elements. This allows modifying each element in place. The example increments each element by 2. ```rust let x = &mut [1, 2, 4]; for elem in x.iter_mut() { *elem += 2; } assert_eq!(x, &[3, 4, 6]); ``` -------------------------------- ### Concurrency and Platform Traits Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/struct.CollisionStart Documentation for traits related to concurrency (Send, Sync) and WebAssembly compatibility. ```APIDOC ## Trait: ConditionalSend for T ### Description Indicates that a type `T` is safe to send across threads. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ## Trait: WasmNotSend for T ### Description Indicates that a type `T` is not safe to send across threads in a WebAssembly environment. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ## Trait: WasmNotSync for T ### Description Indicates that a type `T` is not safe to share across threads (sync) in a WebAssembly environment. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ## Trait: WasmNotSendSync for T ### Description Indicates that a type `T` is neither safe to send nor sync across threads in a WebAssembly environment. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this trait." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for this trait." } ``` ``` -------------------------------- ### Settings Trait Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/struct.CollisionMargin_search=std%3A%3Avec Documentation for the `Settings` trait. ```APIDOC ## impl Settings for T where T: 'static + Send + Sync, ### Description This block details the `Settings` trait, implemented for types that are static, sendable, and synchronizable. ``` -------------------------------- ### Peek Mut Example (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints Demonstrates the usage of peek_mut to get a mutable reference to the last element of a vector without removing it. It shows how to check if the vector is empty and modify the last element. ```rust #![feature(vec_peek_mut)] let mut vec = Vec::new(); assert!(vec.peek_mut().is_none()); vec.push(1); vec.push(5); vec.push(2); assert_eq!(vec.last(), Some(&2)); if let Some(mut val) = vec.peek_mut() { *val = 0; } assert_eq!(vec.last(), Some(&0)); ``` -------------------------------- ### TryFrom and TryInto Conversions Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/broad_phase/enum.BroadPhaseSystems_search=std%3A%3Avec Utilities for attempting conversions between types that may fail. ```APIDOC ### impl TryFrom for T where U: Into #### type Error = Infallible ### Description The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion. ### Method Static method ### Endpoint N/A (Method within an impl block) ### Parameters - **value** (U) - The value to convert from. ### Request Example N/A ### Response #### Success Response (N/A) - **Result** - Ok(T) on success, Err(Error) on failure. #### Response Example N/A ``` ```APIDOC ### impl TryInto for T where U: TryFrom #### type Error = >::Error ### Description The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion. ### Method `self` (implicit) ### Endpoint N/A (Method within an impl block) ### Parameters None ### Request Example N/A ### Response #### Success Response (N/A) - **Result** - Ok(U) on success, Err(Error) on failure. #### Response Example N/A ``` -------------------------------- ### Get Positions of Elements Satisfying Predicate Source: https://docs.rs/avian3d/0.5.0/avian3d/data_structures/graph/struct.EdgesBetween Returns an iterator adaptor that yields the indices of all elements satisfying a predicate, counted from the start of the iterator. This is useful for finding multiple occurrences. ```rust fn positions

(self, predicate: P) -> Positions where Self: Sized, P: FnMut(Self::Item) -> bool, ``` -------------------------------- ### Get an orthogonal vector in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/physics_transform/struct.Position_search=u32+-%3E+bool This example demonstrates how to obtain a vector that is orthogonal (perpendicular) to a given vector using the `any_orthogonal_vector` method. This is useful in various geometric calculations where perpendicular vectors are needed. ```rust use avian3d::math::Vec3; let vector = Vec3::new(1.0, 0.0, 0.0); let orthogonal_vector = vector.any_orthogonal_vector(); // orthogonal_vector will be a vector perpendicular to the X-axis, e.g., Vec3::new(0.0, 1.0, 0.0) ``` -------------------------------- ### Generic CloneToUninit Implementation Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/constraint_graph/struct.GraphColor_search= Experimental (nightly-only) implementation for cloning to uninitialized memory. ```APIDOC ## Generic CloneToUninit Implementation ### Description An experimental (nightly-only) implementation that allows cloning a value directly into uninitialized memory. ### Method - `unsafe fn clone_to_uninit(&self, dest: *mut u8)`: Performs copy-assignment from `self` to `dest`. ### Warning This is a nightly-only experimental API and requires `unsafe` code. ``` -------------------------------- ### Enabling Collision Events Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/index_search=u32+-%3E+bool This example shows how to enable collision events for a specific entity by adding the `CollisionEventsEnabled` component. This allows the entity to both send and receive collision start and end events. ```APIDOC ## POST /enable_collision_events ### Description Enables collision events for a given entity. ### Method POST ### Endpoint `/enable_collision_events` ### Parameters #### Request Body - **entity_id** (string) - Required - The unique identifier of the entity. ### Request Example ```json { "entity_id": "some_entity_id" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "Collision events enabled successfully" } ``` ``` -------------------------------- ### From and FromWorld Traits Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/rigid_body/forces/struct.ConstantLocalForce_search=std%3A%3Avec Documentation for `From` and `FromWorld` traits for creating instances. ```APIDOC ## From for T ### Description Provides a conversion from `T` to `T`. ### Method `fn from(t: T) -> T` Returns the argument unchanged. ## FromWorld for T ### Description Provides a way to create an instance from the `World`. ### Method `fn from_world(_world: &mut World) -> T` Creates `Self` using `default()`. ``` -------------------------------- ### Type Conversion and Subscriber Integration Source: https://docs.rs/avian3d/0.5.0/avian3d/data_structures/graph/struct.EdgeWeightsMut_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for type conversion traits (TryFrom, TryInto) and methods for integrating subscribers. ```APIDOC ## Type Conversion and Subscriber Integration ### Description Details traits and methods related to type conversions and attaching subscribers to types. ### Traits and Implementations #### `impl Same for T` * **Type Alias**: `Output = T` * **Description**: Should always be `Self`. #### `impl SupersetOf for SP` * **Description**: Represents a superset relationship between types. * **Methods**: * **`to_subset(&self) -> Option`**: Attempts to construct `self` from the equivalent element of its superset. * **`is_in_subset(&self) -> bool`**: Checks if `self` is actually part of its subset `T`. * **`to_subset_unchecked(&self) -> SS`**: Unchecked conversion to subset. Use with care. * **`from_subset(element: &SS) -> SP`**: Converts `self` to the equivalent element of its superset. #### `impl TryFrom for T` * **Description**: Enables fallible conversion from type `U` into type `T`. * **Type Alias**: `Error = Infallible` * **Description**: The type returned in the event of a conversion error. * **Method**: * **`try_from(value: U) -> Result>::Error>`**: Performs the conversion. #### `impl TryInto for T` * **Description**: Enables fallible conversion from type `T` into type `U`. * **Type Alias**: `Error = >::Error` * **Description**: The type returned in the event of a conversion error. * **Method**: * **`try_into(self) -> Result>::Error>`**: Performs the conversion. #### `impl WithSubscriber for T` * **Description**: Provides methods for attaching subscribers. * **Methods**: * **`with_subscriber(self, subscriber: S) -> WithDispatch`**: Attaches the provided `Subscriber` to this type. * **Parameters**: `subscriber` (S: Into) - The subscriber to attach. * **`with_current_subscriber(self) -> WithDispatch`**: Attaches the current default `Subscriber` to this type. ``` -------------------------------- ### Create a RigidBody with Collider and Transform Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/rigid_body/enum.RigidBody_search=std%3A%3Avec Example of spawning a dynamic rigid body in Bevy, including a capsule collider and a transform component to set its initial position. This demonstrates the basic setup for physics objects. ```rust use avian3d::prelude::*; use bevy::prelude::*; fn setup(mut commands: Commands) { // Spawn a dynamic rigid body and specify its position. commands.spawn(( RigidBody::Dynamic, Collider::capsule(0.5, 1.5), Transform::from_xyz(0.0, 3.0, 0.0), )); } ``` -------------------------------- ### Example of LinearDamping Usage in Bevy (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/rigid_body/struct.LinearDamping Demonstrates how to use the LinearDamping struct within a Bevy application setup. This snippet shows spawning a dynamic rigid body with a specified linear damping coefficient. ```Rust use avian3d::prelude::*; use bevy::prelude::*; fn setup(mut commands: Commands) { commands.spawn((RigidBody::Dynamic, LinearDamping(0.8))); } ``` -------------------------------- ### Reflection and Settings Source: https://docs.rs/avian3d/0.5.0/avian3d/interpolation/struct.TransformInterpolation_search=std%3A%3Avec Traits for runtime reflection capabilities and configuration settings. ```APIDOC ## Reflection and Settings ### Description Traits enabling runtime introspection of types and management of application settings. ### `Reflectable` Trait - Requires `Reflect`, `GetTypeRegistration`, and `Typed` traits. - Enables runtime reflection on types. ### `Settings` Trait - Requires `'static + Send + Sync` bounds. - Used for managing application or component settings. ### Example Usage ```rust // Assuming `MyType` implements `Reflectable` let reflectable_instance: &dyn Reflect = &my_instance; // Use reflection APIs... // Assuming `AppSettings` implements `Settings` let settings: AppSettings = ...; // Access or modify settings... ``` ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/joint_graph/struct.JointComponentId_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides fallible conversion between types. ```APIDOC ## impl TryFrom for T where U: Into ### Description Provides a fallible conversion from type `U` to type `T`. The conversion can fail, returning a `Result` with an associated `Error` type. ### Method `Error` (associated type), `try_from` ### Endpoint N/A (Trait Implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) N/A #### Response Example None ## impl TryInto for T where U: TryFrom ### Description Provides a fallible conversion from type `T` to type `U` using the `TryFrom` trait. This is the inverse of `TryFrom`. ### Method `try_into` ### Endpoint N/A (Trait Implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) N/A #### Response Example None ``` -------------------------------- ### Observe CollisionStart Event with Bevy in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collision_events/struct.CollisionStart_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to observe CollisionStart events using Bevy's observer pattern. This example sets up a pressure plate sensor and reacts when a player entity starts colliding with it. ```rust use avian3d::prelude::*; use bevy::prelude::*; #[derive(Component)] struct Player; #[derive(Component)] struct PressurePlate; fn setup_pressure_plates(mut commands: Commands) { commands.spawn(( PressurePlate, Collider::cuboid(1.0, 0.1, 1.0), Sensor, // Enable collision events for this entity. CollisionEventsEnabled, )) .observe(on_player_stepped_on_plate); } fn on_player_stepped_on_plate(event: On, player_query: Query<&Player>) { // `colider1` and `body1` refer to the event target and its body. // `collider2` and `body2` refer to the other collider and its body. let pressure_plate = event.collider1; let other_entity = event.collider2; if player_query.contains(other_entity) { println!("Player {other_entity} stepped on pressure plate {pressure_plate}"); } } ``` -------------------------------- ### CloneToUninit Trait Implementations Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/struct.CollisionMargin_search=u32+-%3E+bool Documentation for the experimental `CloneToUninit` trait for cloning into uninitialized memory. ```APIDOC ## CloneToUninit Trait (Nightly Only) ### Description An experimental, nightly-only trait that allows cloning a value directly into uninitialized memory. ### Methods #### `unsafe fn clone_to_uninit(&self, dest: *mut u8)` - **Description**: Performs copy-assignment from `self` to the memory location pointed to by `dest`. - **Safety**: This method is unsafe and requires that `dest` points to a valid, uninitialized memory location of the correct size. - **Source**: [Link to source code] ``` -------------------------------- ### Get Element Offset in Rust Slice Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints Illustrates the `element_offset` method, which returns the index of an element reference within a slice. It uses pointer arithmetic and returns `None` if the element reference is not aligned with the start of an element. This is useful for extending slice iterators. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Type Conversion and Ownership Source: https://docs.rs/avian3d/0.5.0/avian3d/data_structures/graph/struct.EdgeWeights_search=u32+-%3E+bool Documentation for type conversion traits like `TryFrom`, `TryInto`, and `ToOwned`. ```APIDOC ## Type Conversion and Ownership ### `impl ToOwned for T` **Description**: Provides methods to create owned data from borrowed data. #### `type Owned = T` **Description**: The resulting type after obtaining ownership. #### `fn to_owned(&self) -> T` **Description**: Creates owned data from borrowed data, usually by cloning. #### `fn clone_into(&self, target: &mut T)` **Description**: Uses borrowed data to replace owned data, usually by cloning. ### `impl TryFrom for T` **Description**: Enables fallible conversion from one type to another. #### `type Error = Infallible` **Description**: The type returned in the event of a conversion error. #### `fn try_from(value: U) -> Result>::Error>` **Description**: Performs the conversion. ### `impl TryInto for T` **Description**: Enables fallible conversion into another type. #### `type Error = >::Error` **Description**: The type returned in the event of a conversion error. #### `fn try_into(self) -> Result>::Error>` **Description**: Performs the conversion. ``` -------------------------------- ### Get Vector Capacity in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.RayHits Shows how to retrieve the current capacity of a vector using the `capacity()` method. The example demonstrates that the capacity is at least the requested amount when using `Vec::with_capacity`. It also includes a note about zero-sized elements affecting capacity. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` -------------------------------- ### Get Element Index from Reference in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.RayHits Determines the index of a given element reference within a slice using pointer arithmetic. Returns `None` if the element reference does not point to the start of an element within the slice. Panics if the element type `T` is zero-sized. ```rust pub fn element_offset(&self, element: &T) -> Option ``` -------------------------------- ### Reflection and Settings Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/struct.ColliderDisabled_search=u32+-%3E+bool Covers traits related to runtime reflection (`Reflectable`) and configuration settings (`Settings`). ```APIDOC ## Reflectable for T ### Description Trait for types that support runtime reflection. ### Method (No specific methods documented, implies trait bounds) ## Settings for T ### Description Trait for types that hold configuration settings. ### Method (No specific methods documented, implies trait bounds) ``` -------------------------------- ### Standard Library Trait Implementations Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/narrow_phase/struct.NarrowPhasePlugin Documentation for common Rust traits like `From`, `Into`, `TryFrom`, and `TryInto` as implemented for various types. ```APIDOC ## `From` for `T` ### `from` Returns the argument unchanged. ## `Into` for `T` ### `into` Calls `U::from(self)`. This conversion is determined by the implementation of `From for U`. ## `TryFrom` for `T` ### `try_from` Performs the conversion. Returns `Result>::Error>`. ### `Error` The type returned in the event of a conversion error. Defaults to `Infallible`. ## `TryInto` for `T` ### `Error` The type returned in the event of a conversion error. This is the same as `>::Error`. ``` -------------------------------- ### Get Element Index by Pointer (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/collision/collider/collider_hierarchy/struct.RigidBodyColliders The `element_offset` method returns the index of an element within a slice if the provided reference points to the start of an element. It uses pointer arithmetic and does not compare element values. Returns `None` if the element is not aligned within the slice. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Conversions (TryInto) Source: https://docs.rs/avian3d/0.5.0/avian3d/struct.PhysicsPluginsWithHooks_search= Provides a fallible conversion from `T` to `U` where `U` implements `TryFrom`. ```APIDOC ## Conversions (TryInto) ### Description Performs a fallible conversion from `T` to `U`. The error type is determined by `U`'s `TryFrom` implementation. ### Associated Type `type Error = >::Error` ### Method - `fn try_into(self) -> Result>::Error>` ### Example ```rust // Example usage would go here if available ``` ``` -------------------------------- ### Safe Get Disjoint Mutable Slice Elements in Rust Source: https://docs.rs/avian3d/0.5.0/avian3d/dynamics/solver/struct.ContactConstraints_search=u32+-%3E+bool Provides an example of the safe `get_disjoint_mut` method in Rust, which returns mutable references to multiple disjoint elements or sub-slices within a slice. It returns a `Result` to indicate success or failure due to out-of-bounds or overlapping indices. ```rust let mut slice = vec![1, 2, 3, 4, 5]; let result = slice.get_disjoint_mut([0, 2, 4]); match result { Ok(mut refs) => { refs[0] = &mut 10; refs[1] = &mut 20; refs[2] = &mut 40; } Err(_) => panic!("Failed to get disjoint mutable references"), } assert_eq!(slice, vec![10, 2, 20, 4, 40]); ``` ```rust let mut slice = vec![1, 2, 3, 4, 5]; let result = slice.get_disjoint_mut([0..2, 3..5]); match result { Ok(mut refs) => { refs[0][0] = 11; refs[0][1] = 22; refs[1][0] = 44; refs[1][1] = 55; } Err(_) => panic!("Failed to get disjoint mutable references"), } assert_eq!(slice, vec![11, 22, 3, 44, 55]); ``` ```rust let mut slice = vec![1, 2, 3, 4, 5]; let result = slice.get_disjoint_mut([0, 2, 1]); // Overlapping indices assert!(result.is_err()); ``` ```rust let mut slice = vec![1, 2, 3, 4, 5]; let result = slice.get_disjoint_mut([0, 6]); // Out of bounds index assert!(result.is_err()); ``` -------------------------------- ### Get Element Offset (Rust) Source: https://docs.rs/avian3d/0.5.0/avian3d/spatial_query/struct.RayHits_search= Determines the index of a given element reference within a slice using pointer arithmetic. It returns `Some(index)` if the element reference points to the start of an element in the slice, and `None` otherwise. This method does not compare element values and panics if `T` is zero-sized. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ```