visual_cortex_capture/target.rs
1/// What to capture: a display by index, or a window matched by exact title.
2///
3/// Construction is infallible — a matching window need not exist yet (it may
4/// appear later and reattach). Resolution failure surfaces at capture time as
5/// [`CaptureError::TargetNotFound`](crate::CaptureError::TargetNotFound).
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum Target {
8 /// The Nth display reported by the platform (0 = first).
9 Display(usize),
10 /// The first window whose title matches exactly.
11 WindowTitled(String),
12}
13
14impl Target {
15 /// Capture the display at `index` (0 = first).
16 pub fn display(index: usize) -> Self {
17 Target::Display(index)
18 }
19
20 /// Capture the first window whose title exactly equals `title`.
21 pub fn window_titled(title: impl Into<String>) -> Self {
22 Target::WindowTitled(title.into())
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn constructors_build_expected_variants() {
32 assert_eq!(Target::display(2), Target::Display(2));
33 assert_eq!(
34 Target::window_titled("Elden Ring"),
35 Target::WindowTitled("Elden Ring".to_string())
36 );
37 }
38}