icedwright-probe 0.1.4

What an iced app links for icedwright: semantic annotations, typed test ids and named tasks, all pass-through unless a feature turns them on
Documentation
//! What an iced app links so icedwright can see and steer it.
//!
//! - [`semantic`], [`test_id`] and [`SemanticExt::semantic`] describe what iced cannot infer:
//!   a role, a name, states, a typed [`TestId`]. Widget authors call [`report`] from their own
//!   `operate`.
//! - [`task_name!`] declares a [`TaskName`], and `SaveNote::task(future)` names a future so a
//!   test can hold, release, fail or replace it with a value of the right type.
//! - [`time`] is the clock components should read, which a harness can move.
//! - `#[derive(TestId)]` and `#[derive(Messages)]` come from `icedwright-probe-macros`.
//!
//! With no features everything here is pass-through: `semantic(el)` converts back into `el`,
//! the builder methods do nothing, and `SaveNote::task(future)` returns the future itself. The
//! `semantics` feature sends annotations to the recorder, `control` lets a harness control
//! named tasks, and `remote` adds the endpoint and both of the others. Turn them on from
//! dev-dependencies so release builds never see them.

#![deny(missing_docs)]
#![warn(clippy::must_use_candidate, clippy::return_self_not_must_use)]

mod annotation;
#[cfg(feature = "control")]
#[doc(hidden)]
pub mod control;
#[cfg(feature = "semantics")]
mod hit;
#[cfg(feature = "semantics")]
mod recorder;
#[cfg(feature = "remote")]
pub mod remote;
mod semantic;
mod task;
mod test_id;
pub mod time;
#[cfg(feature = "semantics")]
#[path = "remote/event.rs"]
pub mod wire;

pub use annotation::{Annotation, CaretClock, ClickClock, Key, report};
pub use icedwright_probe_macros::{Messages, TestId};
pub use icedwright_types::role;
pub use icedwright_types::{Checked, CursorSeen, Messages, Role, VariantPath};
pub use semantic::{Semantic, SemanticExt, semantic, test_id};
#[cfg(feature = "control")]
pub use task::Named;
pub use task::{Fallible, NamedTask, TaskName};
pub use test_id::{IntoTestId, TestId, TestIdRef};

#[cfg(feature = "semantics")]
pub use annotation::Ask;
#[cfg(feature = "semantics")]
pub use hit::{HitProbe, LayerCursor};
#[cfg(feature = "semantics")]
pub use recorder::{OverlayMarker, RawRecorder, WindowMarker};

/// Paths the derives and `task_name!` expand to. Not part of the public API.
#[doc(hidden)]
pub mod __private {
    use std::any::TypeId;
    use std::collections::BTreeMap;
    use std::sync::{Mutex, PoisonError};

    pub use std::borrow::Cow;
    pub use std::sync::LazyLock;

    pub use icedwright_types::VariantPath;

    /// The variant table of a generic message enum, built once per concrete type. A `static`
    /// cannot depend on generic parameters, so the table is kept by `TypeId` and leaked.
    pub fn variants_for<T: 'static>(
        build: impl FnOnce() -> Vec<VariantPath>,
    ) -> &'static [VariantPath] {
        static TABLES: Mutex<BTreeMap<TypeId, &'static [VariantPath]>> =
            Mutex::new(BTreeMap::new());
        let key = TypeId::of::<T>();
        if let Some(found) = TABLES
            .lock()
            .unwrap_or_else(PoisonError::into_inner)
            .get(&key)
        {
            return found;
        }
        // Built outside the lock: a nested generic enum's table is built through this function.
        let built: &'static [VariantPath] = Box::leak(build().into_boxed_slice());
        TABLES
            .lock()
            .unwrap_or_else(PoisonError::into_inner)
            .entry(key)
            .or_insert(built)
    }
}