pub trait Particle {
    type Array: Array;

    // Required methods
    fn position(&self) -> Self::Array;
    fn mu(&self) -> <Self::Array as Array>::Item;
}
Expand description

Trait to describe a particle which consists of a position and a gravitational parameter mu.

§Deriving:

Used when the type has fields named position and mu:

#[derive(Particle)]
#[dim(3)]
struct Body {
    position: Vec3,
    mu: f32,
//  ...
}
§Manual implementation:

Used when the type cannot directly provide a position and a gravitational parameter.

struct Body {
    position: Vec3,
    mass: f32,
//  ...
}

impl Particle for Body {
    type Array = [f32; 3];

    fn position(&self) -> [f32; 3] {
        self.position.into()
    }
     
    fn mu(&self) -> f32 {
        self.mass * G
    }
}

If you can’t implement Particle on a type, you can use the fact that it is implemented for tuples of an array and its scalar type instead of creating an intermediate type.

let particle = ([1.0, 1.0, 0.0], 5.0);

assert_eq!(particle.position(), [1.0, 1.0, 0.0]);
assert_eq!(particle.mu(), 5.0);

Required Associated Types§

source

type Array: Array

Type of the position.

Required Methods§

source

fn position(&self) -> Self::Array

The position of the particle in space.

source

fn mu(&self) -> <Self::Array as Array>::Item

The standard gravitational parameter of the particle, annotated µ.

µ = gravitational constant * mass.

Implementations on Foreign Types§

source§

impl<P: Particle> Particle for &P

§

type Array = <P as Particle>::Array

source§

fn position(&self) -> Self::Array

source§

fn mu(&self) -> <Self::Array as Array>::Item

source§

impl<P: Particle> Particle for &mut P

§

type Array = <P as Particle>::Array

source§

fn position(&self) -> Self::Array

source§

fn mu(&self) -> <Self::Array as Array>::Item

source§

impl<const D: usize, S: Clone> Particle for ([S; D], S)

§

type Array = [S; D]

source§

fn position(&self) -> Self::Array

source§

fn mu(&self) -> <Self::Array as Array>::Item

Implementors§