Skip to main content

icedwright_probe/
lib.rs

1//! What an iced app links so icedwright can see and steer it.
2//!
3//! - [`semantic`], [`test_id`] and [`SemanticExt::semantic`] describe what iced cannot infer:
4//!   a role, a name, states, a typed [`TestId`]. Widget authors call [`report`] from their own
5//!   `operate`.
6//! - [`task_name!`] declares a [`TaskName`], and `SaveNote::task(future)` names a future so a
7//!   test can hold, release, fail or replace it with a value of the right type.
8//! - [`time`] is the clock components should read, which a harness can move.
9//! - `#[derive(TestId)]` and `#[derive(Messages)]` come from `icedwright-probe-macros`.
10//!
11//! With no features everything here is pass-through: `semantic(el)` converts back into `el`,
12//! the builder methods do nothing, and `SaveNote::task(future)` returns the future itself. The
13//! `semantics` feature sends annotations to the recorder, `control` lets a harness control
14//! named tasks, and `remote` adds the endpoint and both of the others. Turn them on from
15//! dev-dependencies so release builds never see them.
16
17#![deny(missing_docs)]
18#![warn(clippy::must_use_candidate, clippy::return_self_not_must_use)]
19
20mod annotation;
21#[cfg(feature = "control")]
22#[doc(hidden)]
23pub mod control;
24#[cfg(feature = "semantics")]
25mod hit;
26#[cfg(feature = "semantics")]
27mod recorder;
28#[cfg(feature = "remote")]
29pub mod remote;
30mod semantic;
31mod task;
32mod test_id;
33pub mod time;
34#[cfg(feature = "semantics")]
35#[path = "remote/event.rs"]
36pub mod wire;
37
38pub use annotation::{Annotation, CaretClock, ClickClock, Key, report};
39pub use icedwright_probe_macros::{Messages, TestId};
40pub use icedwright_types::role;
41pub use icedwright_types::{Checked, CursorSeen, Messages, Role, VariantPath};
42pub use semantic::{Semantic, SemanticExt, semantic, test_id};
43#[cfg(feature = "control")]
44pub use task::Named;
45pub use task::{Fallible, NamedTask, TaskName};
46pub use test_id::{IntoTestId, TestId, TestIdRef};
47
48#[cfg(feature = "semantics")]
49pub use annotation::Ask;
50#[cfg(feature = "semantics")]
51pub use hit::{HitProbe, LayerCursor};
52#[cfg(feature = "semantics")]
53pub use recorder::{OverlayMarker, RawRecorder, WindowMarker};
54
55/// Paths the derives and `task_name!` expand to. Not part of the public API.
56#[doc(hidden)]
57pub mod __private {
58    use std::any::TypeId;
59    use std::collections::BTreeMap;
60    use std::sync::{Mutex, PoisonError};
61
62    pub use std::borrow::Cow;
63    pub use std::sync::LazyLock;
64
65    pub use icedwright_types::VariantPath;
66
67    /// The variant table of a generic message enum, built once per concrete type. A `static`
68    /// cannot depend on generic parameters, so the table is kept by `TypeId` and leaked.
69    pub fn variants_for<T: 'static>(
70        build: impl FnOnce() -> Vec<VariantPath>,
71    ) -> &'static [VariantPath] {
72        static TABLES: Mutex<BTreeMap<TypeId, &'static [VariantPath]>> =
73            Mutex::new(BTreeMap::new());
74        let key = TypeId::of::<T>();
75        if let Some(found) = TABLES
76            .lock()
77            .unwrap_or_else(PoisonError::into_inner)
78            .get(&key)
79        {
80            return found;
81        }
82        // Built outside the lock: a nested generic enum's table is built through this function.
83        let built: &'static [VariantPath] = Box::leak(build().into_boxed_slice());
84        TABLES
85            .lock()
86            .unwrap_or_else(PoisonError::into_inner)
87            .entry(key)
88            .or_insert(built)
89    }
90}