This library is used to define types that implement the trait FiniteElement
The types are defined by procedural macros. To create a new type, one must first define an
unit-like Structure and implement the trait AutoImplementable
for it. Once the trait
AutoImplementable
has been implemented it is possible to define a proc macro that will
generate the deffinition of a new type and an implementation of the trait FiniteElement
for
it.
Creation of a new macro
To create a new macro, one must first define a Zero-Sized struct
, and implement the trait
AutoImplementable
for it. For example if we want to create an element representing a spring,
we first create a zero-sized struct
: pub struct _Spring{}
and the implement the trait
Autotimplementable
for it.
The types that implement the trait AutoImplementable
can be passed as type argument to the
function macro_def<F: Float, T: AutoImplementable<F>>() -> TokenStream
. This function
can be used to define a procedural macro that will generate the code defining the
corresponding structure and its implementation of the trait FiniteElement
.
Complete example
(copied-pasted from spring.rs
)
use crate;
use crate AutoImplementable;
use HashMap;
// A `Spring` likes it when `a` and `b` are at distance `l`, and
// exerts a force of `k.(|ab| - l)` to achieve this.
// Once the trait is implemented, we can write a procedural macro