diff --git a/aimdb-data-contracts/src/observable.rs b/aimdb-data-contracts/src/observable.rs index dff6b68e..42132b0b 100644 --- a/aimdb-data-contracts/src/observable.rs +++ b/aimdb-data-contracts/src/observable.rs @@ -64,6 +64,28 @@ where /// `#[record_key(contract = T)]`); on a `Name` record it does not /// compile. /// + /// ```compile_fail,E0277 + /// use aimdb_core::{RecordRegistrar, Undeclared}; + /// use aimdb_data_contracts::{Observable, ObservableRegistrarExt, SchemaType}; + /// + /// #[derive(Clone, Debug)] + /// struct Temp(f32); + /// impl SchemaType for Temp { + /// const NAME: &'static str = "temp"; + /// } + /// impl Observable for Temp { + /// type Signal = f32; + /// fn signal(&self) -> f32 { + /// self.0 + /// } + /// } + /// + /// // A `Name` record: its registrar is `Undeclared`. + /// fn wire(reg: &mut RecordRegistrar<'_, Temp, Undeclared>) { + /// reg.observe(); + /// } + /// ``` + /// /// Recording requires `aimdb-core`'s `observability` feature: without it /// [`RecordRegistrar::signal_gauge`] hands back an inert gauge and this /// tap compiles and runs but records nothing. `.log()` does not depend on diff --git a/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.rs b/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.rs index 8749dc27..cc0d2e83 100644 --- a/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.rs +++ b/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.rs @@ -1,9 +1,10 @@ //! Contract verbs need a record whose key declares the contract: on a -//! `Name` record (schema-free), they do not compile. +//! `Name` record (schema-free), they do not compile. (`.observe()` is +//! covered by a doctest on `ObservableRegistrarExt::observe`, since this +//! suite also runs without the `observable` feature.) use aimdb_core::{AimDbBuilder, ConnectorHandle, Name}; use aimdb_data_contracts::{ - publish, subscribe, LinkCodecRegistrarExt, Linkable, LinkableRegistrarExt, Observable, - ObservableRegistrarExt, SchemaType, + publish, subscribe, LinkCodecRegistrarExt, Linkable, LinkableRegistrarExt, SchemaType, }; #[derive(Clone, Debug)] @@ -19,13 +20,6 @@ impl Linkable for Temp { Ok(Temp(0.0)) } } -impl Observable for Temp { - type Signal = f32; - const UNIT: &'static str = "C"; - fn signal(&self) -> f32 { - self.0 - } -} const TEMP: Name = Name::new("temp"); @@ -34,7 +28,6 @@ fn wire(b: &mut AimDbBuilder, mqtt: ConnectorHandle) { r.linked_to("mqtt://out"); r.linked_from("mqtt://in"); r.linked_to_with("mqtt://out2", aimdb_data_contracts::link_codecs::Default); - r.observe(); r.output(publish(mqtt, "out")); r.input(subscribe(mqtt, "in")); }); diff --git a/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.stderr b/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.stderr index 6d74587a..133090b3 100644 --- a/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.stderr +++ b/aimdb-data-contracts/tests/compile-fail/typed_key_contract_verbs_on_name.stderr @@ -1,7 +1,7 @@ error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:34:11 + --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:28:11 | -34 | r.linked_to("mqtt://out"); +28 | r.linked_to("mqtt://out"); | ^^^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` | = note: contract verbs (`linked_to`, `linked_from`, `publish`, `subscribe`, `observe`) need the record declared with `Key` or `#[record_key(contract = T)]`, not `Name` or `payload = T` @@ -20,9 +20,9 @@ note: required by a bound in `linked_to` | ^^^^^^^^^^^^^^^^ required by this bound in `LinkableRegistrarExt::linked_to` error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:35:11 + --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:29:11 | -35 | r.linked_from("mqtt://in"); +29 | r.linked_from("mqtt://in"); | ^^^^^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` | = note: contract verbs (`linked_to`, `linked_from`, `publish`, `subscribe`, `observe`) need the record declared with `Key` or `#[record_key(contract = T)]`, not `Name` or `payload = T` @@ -41,9 +41,9 @@ note: required by a bound in `linked_from` | ^^^^^^^^^^^^^^^^ required by this bound in `LinkableRegistrarExt::linked_from` error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:36:11 + --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:30:11 | -36 | r.linked_to_with("mqtt://out2", aimdb_data_contracts::link_codecs::Default); +30 | r.linked_to_with("mqtt://out2", aimdb_data_contracts::link_codecs::Default); | ^^^^^^^^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` | = note: contract verbs (`linked_to`, `linked_from`, `publish`, `subscribe`, `observe`) need the record declared with `Key` or `#[record_key(contract = T)]`, not `Name` or `payload = T` @@ -62,30 +62,9 @@ note: required by a bound in `linked_to_with` | ^^^^^^^^^^^^^^^^ required by this bound in `LinkCodecRegistrarExt::linked_to_with` error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:37:11 + --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:31:18 | -37 | r.observe(); - | ^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` - | - = note: contract verbs (`linked_to`, `linked_from`, `publish`, `subscribe`, `observe`) need the record declared with `Key` or `#[record_key(contract = T)]`, not `Name` or `payload = T` -help: the trait `ContractDeclared` is implemented for `Declared` - --> $WORKSPACE/aimdb-core/src/record_id.rs - | - | impl ContractDeclared for Declared {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: required by a bound in `observe` - --> src/observable.rs - | - | fn observe(&mut self) -> &mut Self - | ------- required by a bound in this associated function -... - | S: ContractDeclared; - | ^^^^^^^^^^^^^^^^ required by this bound in `ObservableRegistrarExt::observe` - -error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:38:18 - | -38 | r.output(publish(mqtt, "out")); +31 | r.output(publish(mqtt, "out")); | ------ ^^^^^^^^^^^^^^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` | | | required by a bound introduced by this call @@ -104,9 +83,9 @@ note: required by a bound in `RecordRegistrar::<'a, T, S>::output` | ^^^^^^^^^^^^ required by this bound in `RecordRegistrar::<'a, T, S>::output` error[E0277]: this record's key declares no data contract - --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:39:17 + --> tests/compile-fail/typed_key_contract_verbs_on_name.rs:32:17 | -39 | r.input(subscribe(mqtt, "in")); +32 | r.input(subscribe(mqtt, "in")); | ----- ^^^^^^^^^^^^^^^^^^^^^ the trait `ContractDeclared` is not implemented for `Undeclared` | | | required by a bound introduced by this call