[−][src]Crate summon
summon
A logic engine designed to magically give you what you ask for
#[derive(Clone)] struct ConstantAcceleration(f64); #[derive(Clone)] struct InitialVelocity(f64); #[derive(Clone)] struct InitialPosition(f64); #[derive(Clone)] struct Time(f64); struct Distance(f64); struct RealPhysicsOn; #[test] fn sum() { // The tome is where all the logic and conversions are written in your code. let mut tome = Tome::new(); // You can use ether() to give types as givens. tome.ether(ConstantAcceleration(3.0)); tome.ether(InitialVelocity(5.0)); tome.ether(InitialPosition(6.0)); tome.ether(Time(4.0)); tome.ether(RealPhysicsOn); // Inscribe is used to describe a conversion between types. // If a function produces multiple types via tuple, two extra inscriptions can be made to break it up into two types. tome.inscribe( circle!((_: &RealPhysicsOn, a: &ConstantAcceleration, v: &InitialVelocity, p: &InitialPosition, t: &Time) -> Distance { Distance(0.5 * a.0 * t.0.powi(2) + v.0 * t.0 + p.0) }), ); // So long as it is possible to produce the result with the given inscriptions, it will be produced. let summoned = tome.summon::<Distance>().unwrap(); assert_eq!( 0.5 * 3.0 * 4.0f64.powi(2) + 5.0 * 4.0 + 6.0, summoned, ); }
Macros
circle | Use this to inscribe a transmutation between a set of input types and an output type. |
fusion | Use this to inscribe tag type/zero-sized struct ( |
Structs
Materials | |
Tome | This is where all of the transmutation circles are inscribed. |
Traits
Transmutation | Transmutations require ingredients and produce a product. This is usually a function. |