Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions aimdb-data-contracts/src/observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ where
/// `#[record_key(contract = T)]`); on a `Name<T>` 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<Temp>` 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Contract verbs need a record whose key declares the contract: on a
//! `Name<T>` record (schema-free), they do not compile.
//! `Name<T>` 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)]
Expand All @@ -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<Temp> = Name::new("temp");

Expand All @@ -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"));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>` or `#[record_key(contract = T)]`, not `Name<T>` or `payload = T`
Expand All @@ -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<T>` or `#[record_key(contract = T)]`, not `Name<T>` or `payload = T`
Expand All @@ -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<T>` or `#[record_key(contract = T)]`, not `Name<T>` or `payload = T`
Expand All @@ -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<T>` or `#[record_key(contract = T)]`, not `Name<T>` 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
Expand All @@ -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
Expand Down
Loading