1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Event sink system for typed callback notifications.
//!
//! This module defines the `EventSink` trait, which provides a strongly-typed interface
//! for handling framework notifications, replacing the legacy string-based callbacks.
use crateMaaId;
use crateMaaEvent;
/// A trait for receiving structured events from the framework.
///
/// Implementing this trait allows types to register as listeners on `Tasker` or `Controller` instances.
/// Unlike raw closures which receive raw strings, `EventSink` implementation receives
/// fully parsed `MaaEvent` structures.
///
/// # Thread Safety
/// Implementations must be `Send + Sync` as they may be invoked from internal framework threads.
///
/// # Example
///
/// ```rust
/// use maa_framework::event_sink::EventSink;
/// use maa_framework::notification::MaaEvent;
/// use maa_framework::common::MaaId;
///
/// struct MyLogger;
///
/// impl EventSink for MyLogger {
/// fn on_event(&self, handle: MaaId, event: &MaaEvent) {
/// match event {
/// MaaEvent::TaskerTaskStarting(detail) => {
/// println!("Task started on instance {}: {}", handle, detail.entry);
/// }
/// MaaEvent::TaskerTaskSucceeded(_) => {
/// println!("Task succeeded on instance {}", handle);
/// }
/// _ => { /* Ignore other events */ }
/// }
/// }
/// }
/// ```
// === Helper Functions ===
/// helper to create an `EventSink` from a closure.
///
/// This is a convenience function to create a sink without defining a new struct.
///
/// # Example
///
/// ```rust
/// use maa_framework::event_sink;
///
/// let sink = event_sink::from_closure(|handle, event| {
/// println!("Received event {:?} from {}", event, handle);
/// });
/// ```
/// A wrapper struct needed to implement `EventSink` for closures.
///
/// Produced by [`from_closure`].
;