//! 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::("ui"), compose::Confirm, &c.instance::("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 for OtherInput { fn fields(self) -> atlibs_compose::serde_json::Map { Default::default() } } //! let c = Composition::new("wrong"); //! c.instance::("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::("ui"); let lookup = c.instance::("lookup").input(ComposeInput::default().n(0)); let even = c.instance::("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")); }