screencapturekit/stream/configuration/
types.rs1use std::fmt;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct ConfigError {
10 pub message: String,
11}
12
13impl ConfigError {
14 pub fn new(message: impl Into<String>) -> Self {
15 Self {
16 message: message.into(),
17 }
18 }
19}
20
21impl fmt::Display for ConfigError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "Configuration error: {}", self.message)
24 }
25}
26
27impl std::error::Error for ConfigError {}
28
29#[derive(Debug, Clone, Copy, PartialEq, Default)]
31pub struct Point {
32 pub x: f64,
33 pub y: f64,
34}
35
36impl Eq for Point {}
37
38impl std::hash::Hash for Point {
39 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
40 self.x.to_bits().hash(state);
41 self.y.to_bits().hash(state);
42 }
43}
44
45impl Point {
46 pub const fn new(x: f64, y: f64) -> Self {
47 Self { x, y }
48 }
49}
50
51impl fmt::Display for Point {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 write!(f, "({}, {})", self.x, self.y)
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Default)]
59pub struct Size {
60 pub width: f64,
61 pub height: f64,
62}
63
64impl Eq for Size {}
65
66impl std::hash::Hash for Size {
67 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
68 self.width.to_bits().hash(state);
69 self.height.to_bits().hash(state);
70 }
71}
72
73impl Size {
74 pub const fn new(width: f64, height: f64) -> Self {
75 Self { width, height }
76 }
77}
78
79impl fmt::Display for Size {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 write!(f, "{}x{}", self.width, self.height)
82 }
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Default)]
87pub struct Rect {
88 pub origin: Point,
89 pub size: Size,
90}
91
92impl Eq for Rect {}
93
94impl std::hash::Hash for Rect {
95 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
96 self.origin.hash(state);
97 self.size.hash(state);
98 }
99}
100
101impl Rect {
102 pub const fn new(origin: Point, size: Size) -> Self {
103 Self { origin, size }
104 }
105
106 pub const fn zero() -> Self {
107 Self {
108 origin: Point { x: 0.0, y: 0.0 },
109 size: Size {
110 width: 0.0,
111 height: 0.0,
112 },
113 }
114 }
115}
116
117impl fmt::Display for Rect {
118 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119 write!(
120 f,
121 "({}, {}, {})",
122 self.origin, self.size.width, self.size.height
123 )
124 }
125}