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
//! examples/rust/compose/composition.json, in Rust. Wrong compositions do not compile:
//!
//! compose does not implement confirm:
//! ```compile_fail,E0277
//! use atlibs_compose::Composition;
//! use rust_compose::modules::{nsid::com::example::compose, Compose};
//! let c = Composition::new("wrong");
//! c.route(&c.instance::<Compose>("ui"), compose::Confirm, &c.instance::<Compose>("x"), "");
//! ```
//!
//! n is an integer:
//! ```compile_fail,E0277
//! use rust_compose::modules::ComposeInput;
//! ComposeInput::default().n("4");
//! ```
//!
//! an input of another module:
//! ```compile_fail,E0277
//! use atlibs_compose::{Composition, Input};
//! struct Other;
//! impl atlibs_compose::Module for Other { const KEY: &'static str = "other"; const PIN: Option<&'static str> = None; }
//! #[derive(Default)] struct OtherInput;
//! impl Input<Other> for OtherInput { fn fields(self) -> atlibs_compose::serde_json::Map<String, atlibs_compose::serde_json::Value> { Default::default() } }
//! let c = Composition::new("wrong");
//! c.instance::<rust_compose::modules::Compose>("x").input(OtherInput);
//! ```
use atlibs_compose::Composition;
pub mod modules {
include!(concat!(env!("OUT_DIR"), "/modules.rs"));
}
use modules::{Compose, ComposeInput, nsid::com::example::compose};
pub fn toys() -> Composition {
let c = Composition::new("Compose toys")
.description("ui asks lookup to double n (only even n, per the even policy), passing a progress callback; lookup may ask the page to confirm.")
.limits(4, 20);
let ui = c.instance::<Compose>("ui");
let lookup = c.instance::<Compose>("lookup").input(ComposeInput::default().n(0));
let even = c.instance::<Compose>("even");
let confirm = c.handler("confirm", "The page asks the user.");
c.route(&ui, compose::Lookup, &lookup, "ui needs n doubled").policy(&even, Compose::even);
c.route_handler(&ui, compose::Confirm, &confirm, "ui asks the user before acting");
c
}
#[test]
fn writes_the_composition_json() {
assert_eq!(toys().to_json(), include_str!("../../rust/compose/composition.json"));
}