Skip to main content

rustenium_cdp_definitions/browser_protocol/layer_tree/
command_builders.rs

1use super::commands::*;
2impl CompositingReasons {
3    pub fn builder() -> CompositingReasonsBuilder {
4        <CompositingReasonsBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct CompositingReasonsBuilder {
9    layer_id: Option<super::types::LayerId>,
10}
11impl CompositingReasonsBuilder {
12    pub fn layer_id(mut self, layer_id: impl Into<super::types::LayerId>) -> Self {
13        self.layer_id = Some(layer_id.into());
14        self
15    }
16    pub fn build(self) -> Result<CompositingReasons, String> {
17        Ok(CompositingReasons {
18            method: CompositingReasonsMethod::CompositingReasons,
19            params: CompositingReasonsParams {
20                layer_id: self.layer_id.ok_or_else(|| {
21                    format!("Field `{}` is mandatory.", std::stringify!(layer_id))
22                })?,
23            },
24        })
25    }
26}
27#[derive(Debug, Clone, Default)]
28pub struct DisableBuilder;
29impl DisableBuilder {
30    pub fn new() -> Self {
31        Self
32    }
33    pub fn build(self) -> Disable {
34        Disable {
35            method: DisableMethod::Disable,
36            params: DisableParams {},
37        }
38    }
39}
40impl Disable {
41    pub fn builder() -> DisableBuilder {
42        DisableBuilder
43    }
44}
45#[derive(Debug, Clone, Default)]
46pub struct EnableBuilder;
47impl EnableBuilder {
48    pub fn new() -> Self {
49        Self
50    }
51    pub fn build(self) -> Enable {
52        Enable {
53            method: EnableMethod::Enable,
54            params: EnableParams {},
55        }
56    }
57}
58impl Enable {
59    pub fn builder() -> EnableBuilder {
60        EnableBuilder
61    }
62}
63impl LoadSnapshot {
64    pub fn builder() -> LoadSnapshotBuilder {
65        <LoadSnapshotBuilder as Default>::default()
66    }
67}
68#[derive(Default, Clone)]
69pub struct LoadSnapshotBuilder {
70    tiles: Option<Vec<super::types::PictureTile>>,
71}
72impl LoadSnapshotBuilder {
73    pub fn tile(mut self, tile: impl Into<super::types::PictureTile>) -> Self {
74        let v = self.tiles.get_or_insert(Vec::new());
75        v.push(tile.into());
76        self
77    }
78    pub fn tiles<I, S>(mut self, tiles: I) -> Self
79    where
80        I: IntoIterator<Item = S>,
81        S: Into<super::types::PictureTile>,
82    {
83        let v = self.tiles.get_or_insert(Vec::new());
84        for val in tiles {
85            v.push(val.into());
86        }
87        self
88    }
89    pub fn build(self) -> Result<LoadSnapshot, String> {
90        Ok(LoadSnapshot {
91            method: LoadSnapshotMethod::LoadSnapshot,
92            params: LoadSnapshotParams {
93                tiles: self
94                    .tiles
95                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(tiles)))?,
96            },
97        })
98    }
99}
100impl MakeSnapshot {
101    pub fn builder() -> MakeSnapshotBuilder {
102        <MakeSnapshotBuilder as Default>::default()
103    }
104}
105#[derive(Default, Clone)]
106pub struct MakeSnapshotBuilder {
107    layer_id: Option<super::types::LayerId>,
108}
109impl MakeSnapshotBuilder {
110    pub fn layer_id(mut self, layer_id: impl Into<super::types::LayerId>) -> Self {
111        self.layer_id = Some(layer_id.into());
112        self
113    }
114    pub fn build(self) -> Result<MakeSnapshot, String> {
115        Ok(MakeSnapshot {
116            method: MakeSnapshotMethod::MakeSnapshot,
117            params: MakeSnapshotParams {
118                layer_id: self.layer_id.ok_or_else(|| {
119                    format!("Field `{}` is mandatory.", std::stringify!(layer_id))
120                })?,
121            },
122        })
123    }
124}
125impl ProfileSnapshot {
126    pub fn builder() -> ProfileSnapshotBuilder {
127        <ProfileSnapshotBuilder as Default>::default()
128    }
129}
130#[derive(Default, Clone)]
131pub struct ProfileSnapshotBuilder {
132    snapshot_id: Option<super::types::SnapshotId>,
133    min_repeat_count: Option<i64>,
134    min_duration: Option<f64>,
135    clip_rect: Option<crate::browser_protocol::dom::types::Rect>,
136}
137impl ProfileSnapshotBuilder {
138    pub fn snapshot_id(mut self, snapshot_id: impl Into<super::types::SnapshotId>) -> Self {
139        self.snapshot_id = Some(snapshot_id.into());
140        self
141    }
142    pub fn min_repeat_count(mut self, min_repeat_count: impl Into<i64>) -> Self {
143        self.min_repeat_count = Some(min_repeat_count.into());
144        self
145    }
146    pub fn min_duration(mut self, min_duration: impl Into<f64>) -> Self {
147        self.min_duration = Some(min_duration.into());
148        self
149    }
150    pub fn clip_rect(
151        mut self,
152        clip_rect: impl Into<crate::browser_protocol::dom::types::Rect>,
153    ) -> Self {
154        self.clip_rect = Some(clip_rect.into());
155        self
156    }
157    pub fn build(self) -> Result<ProfileSnapshot, String> {
158        Ok(ProfileSnapshot {
159            method: ProfileSnapshotMethod::ProfileSnapshot,
160            params: ProfileSnapshotParams {
161                snapshot_id: self.snapshot_id.ok_or_else(|| {
162                    format!("Field `{}` is mandatory.", std::stringify!(snapshot_id))
163                })?,
164                min_repeat_count: self.min_repeat_count,
165                min_duration: self.min_duration,
166                clip_rect: self.clip_rect,
167            },
168        })
169    }
170}
171impl ReleaseSnapshot {
172    pub fn builder() -> ReleaseSnapshotBuilder {
173        <ReleaseSnapshotBuilder as Default>::default()
174    }
175}
176#[derive(Default, Clone)]
177pub struct ReleaseSnapshotBuilder {
178    snapshot_id: Option<super::types::SnapshotId>,
179}
180impl ReleaseSnapshotBuilder {
181    pub fn snapshot_id(mut self, snapshot_id: impl Into<super::types::SnapshotId>) -> Self {
182        self.snapshot_id = Some(snapshot_id.into());
183        self
184    }
185    pub fn build(self) -> Result<ReleaseSnapshot, String> {
186        Ok(ReleaseSnapshot {
187            method: ReleaseSnapshotMethod::ReleaseSnapshot,
188            params: ReleaseSnapshotParams {
189                snapshot_id: self.snapshot_id.ok_or_else(|| {
190                    format!("Field `{}` is mandatory.", std::stringify!(snapshot_id))
191                })?,
192            },
193        })
194    }
195}
196impl ReplaySnapshot {
197    pub fn builder() -> ReplaySnapshotBuilder {
198        <ReplaySnapshotBuilder as Default>::default()
199    }
200}
201#[derive(Default, Clone)]
202pub struct ReplaySnapshotBuilder {
203    snapshot_id: Option<super::types::SnapshotId>,
204    from_step: Option<i64>,
205    to_step: Option<i64>,
206    scale: Option<f64>,
207}
208impl ReplaySnapshotBuilder {
209    pub fn snapshot_id(mut self, snapshot_id: impl Into<super::types::SnapshotId>) -> Self {
210        self.snapshot_id = Some(snapshot_id.into());
211        self
212    }
213    pub fn from_step(mut self, from_step: impl Into<i64>) -> Self {
214        self.from_step = Some(from_step.into());
215        self
216    }
217    pub fn to_step(mut self, to_step: impl Into<i64>) -> Self {
218        self.to_step = Some(to_step.into());
219        self
220    }
221    pub fn scale(mut self, scale: impl Into<f64>) -> Self {
222        self.scale = Some(scale.into());
223        self
224    }
225    pub fn build(self) -> Result<ReplaySnapshot, String> {
226        Ok(ReplaySnapshot {
227            method: ReplaySnapshotMethod::ReplaySnapshot,
228            params: ReplaySnapshotParams {
229                snapshot_id: self.snapshot_id.ok_or_else(|| {
230                    format!("Field `{}` is mandatory.", std::stringify!(snapshot_id))
231                })?,
232                from_step: self.from_step,
233                to_step: self.to_step,
234                scale: self.scale,
235            },
236        })
237    }
238}
239impl SnapshotCommandLog {
240    pub fn builder() -> SnapshotCommandLogBuilder {
241        <SnapshotCommandLogBuilder as Default>::default()
242    }
243}
244#[derive(Default, Clone)]
245pub struct SnapshotCommandLogBuilder {
246    snapshot_id: Option<super::types::SnapshotId>,
247}
248impl SnapshotCommandLogBuilder {
249    pub fn snapshot_id(mut self, snapshot_id: impl Into<super::types::SnapshotId>) -> Self {
250        self.snapshot_id = Some(snapshot_id.into());
251        self
252    }
253    pub fn build(self) -> Result<SnapshotCommandLog, String> {
254        Ok(SnapshotCommandLog {
255            method: SnapshotCommandLogMethod::SnapshotCommandLog,
256            params: SnapshotCommandLogParams {
257                snapshot_id: self.snapshot_id.ok_or_else(|| {
258                    format!("Field `{}` is mandatory.", std::stringify!(snapshot_id))
259                })?,
260            },
261        })
262    }
263}