Skip to main content

rustenium_cdp_definitions/browser_protocol/animation/
command_builders.rs

1use super::commands::*;
2#[derive(Debug, Clone, Default)]
3pub struct DisableBuilder;
4impl DisableBuilder {
5    pub fn new() -> Self {
6        Self
7    }
8    pub fn build(self) -> Disable {
9        Disable {
10            method: DisableMethod::Disable,
11            params: DisableParams {},
12        }
13    }
14}
15impl Disable {
16    pub fn builder() -> DisableBuilder {
17        DisableBuilder
18    }
19}
20#[derive(Debug, Clone, Default)]
21pub struct EnableBuilder;
22impl EnableBuilder {
23    pub fn new() -> Self {
24        Self
25    }
26    pub fn build(self) -> Enable {
27        Enable {
28            method: EnableMethod::Enable,
29            params: EnableParams {},
30        }
31    }
32}
33impl Enable {
34    pub fn builder() -> EnableBuilder {
35        EnableBuilder
36    }
37}
38impl GetCurrentTime {
39    pub fn builder() -> GetCurrentTimeBuilder {
40        <GetCurrentTimeBuilder as Default>::default()
41    }
42}
43#[derive(Default, Clone)]
44pub struct GetCurrentTimeBuilder {
45    id: Option<String>,
46}
47impl GetCurrentTimeBuilder {
48    pub fn id(mut self, id: impl Into<String>) -> Self {
49        self.id = Some(id.into());
50        self
51    }
52    pub fn build(self) -> Result<GetCurrentTime, String> {
53        Ok(GetCurrentTime {
54            method: GetCurrentTimeMethod::GetCurrentTime,
55            params: GetCurrentTimeParams {
56                id: self
57                    .id
58                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(id)))?,
59            },
60        })
61    }
62}
63#[derive(Debug, Clone, Default)]
64pub struct GetPlaybackRateBuilder;
65impl GetPlaybackRateBuilder {
66    pub fn new() -> Self {
67        Self
68    }
69    pub fn build(self) -> GetPlaybackRate {
70        GetPlaybackRate {
71            method: GetPlaybackRateMethod::GetPlaybackRate,
72            params: GetPlaybackRateParams {},
73        }
74    }
75}
76impl GetPlaybackRate {
77    pub fn builder() -> GetPlaybackRateBuilder {
78        GetPlaybackRateBuilder
79    }
80}
81impl ReleaseAnimations {
82    pub fn builder() -> ReleaseAnimationsBuilder {
83        <ReleaseAnimationsBuilder as Default>::default()
84    }
85}
86#[derive(Default, Clone)]
87pub struct ReleaseAnimationsBuilder {
88    animations: Option<Vec<String>>,
89}
90impl ReleaseAnimationsBuilder {
91    pub fn animation(mut self, animation: impl Into<String>) -> Self {
92        let v = self.animations.get_or_insert(Vec::new());
93        v.push(animation.into());
94        self
95    }
96    pub fn animations<I, S>(mut self, animations: I) -> Self
97    where
98        I: IntoIterator<Item = S>,
99        S: Into<String>,
100    {
101        let v = self.animations.get_or_insert(Vec::new());
102        for val in animations {
103            v.push(val.into());
104        }
105        self
106    }
107    pub fn build(self) -> Result<ReleaseAnimations, String> {
108        Ok(ReleaseAnimations {
109            method: ReleaseAnimationsMethod::ReleaseAnimations,
110            params: ReleaseAnimationsParams {
111                animations: self.animations.ok_or_else(|| {
112                    format!("Field `{}` is mandatory.", std::stringify!(animations))
113                })?,
114            },
115        })
116    }
117}
118impl ResolveAnimation {
119    pub fn builder() -> ResolveAnimationBuilder {
120        <ResolveAnimationBuilder as Default>::default()
121    }
122}
123#[derive(Default, Clone)]
124pub struct ResolveAnimationBuilder {
125    animation_id: Option<String>,
126}
127impl ResolveAnimationBuilder {
128    pub fn animation_id(mut self, animation_id: impl Into<String>) -> Self {
129        self.animation_id = Some(animation_id.into());
130        self
131    }
132    pub fn build(self) -> Result<ResolveAnimation, String> {
133        Ok(ResolveAnimation {
134            method: ResolveAnimationMethod::ResolveAnimation,
135            params: ResolveAnimationParams {
136                animation_id: self.animation_id.ok_or_else(|| {
137                    format!("Field `{}` is mandatory.", std::stringify!(animation_id))
138                })?,
139            },
140        })
141    }
142}
143impl SeekAnimations {
144    pub fn builder() -> SeekAnimationsBuilder {
145        <SeekAnimationsBuilder as Default>::default()
146    }
147}
148#[derive(Default, Clone)]
149pub struct SeekAnimationsBuilder {
150    animations: Option<Vec<String>>,
151    current_time: Option<f64>,
152}
153impl SeekAnimationsBuilder {
154    pub fn animation(mut self, animation: impl Into<String>) -> Self {
155        let v = self.animations.get_or_insert(Vec::new());
156        v.push(animation.into());
157        self
158    }
159    pub fn animations<I, S>(mut self, animations: I) -> Self
160    where
161        I: IntoIterator<Item = S>,
162        S: Into<String>,
163    {
164        let v = self.animations.get_or_insert(Vec::new());
165        for val in animations {
166            v.push(val.into());
167        }
168        self
169    }
170    pub fn current_time(mut self, current_time: impl Into<f64>) -> Self {
171        self.current_time = Some(current_time.into());
172        self
173    }
174    pub fn build(self) -> Result<SeekAnimations, String> {
175        Ok(SeekAnimations {
176            method: SeekAnimationsMethod::SeekAnimations,
177            params: SeekAnimationsParams {
178                animations: self.animations.ok_or_else(|| {
179                    format!("Field `{}` is mandatory.", std::stringify!(animations))
180                })?,
181                current_time: self.current_time.ok_or_else(|| {
182                    format!("Field `{}` is mandatory.", std::stringify!(current_time))
183                })?,
184            },
185        })
186    }
187}
188impl SetPaused {
189    pub fn builder() -> SetPausedBuilder {
190        <SetPausedBuilder as Default>::default()
191    }
192}
193#[derive(Default, Clone)]
194pub struct SetPausedBuilder {
195    animations: Option<Vec<String>>,
196    paused: Option<bool>,
197}
198impl SetPausedBuilder {
199    pub fn animation(mut self, animation: impl Into<String>) -> Self {
200        let v = self.animations.get_or_insert(Vec::new());
201        v.push(animation.into());
202        self
203    }
204    pub fn animations<I, S>(mut self, animations: I) -> Self
205    where
206        I: IntoIterator<Item = S>,
207        S: Into<String>,
208    {
209        let v = self.animations.get_or_insert(Vec::new());
210        for val in animations {
211            v.push(val.into());
212        }
213        self
214    }
215    pub fn paused(mut self, paused: impl Into<bool>) -> Self {
216        self.paused = Some(paused.into());
217        self
218    }
219    pub fn build(self) -> Result<SetPaused, String> {
220        Ok(SetPaused {
221            method: SetPausedMethod::SetPaused,
222            params: SetPausedParams {
223                animations: self.animations.ok_or_else(|| {
224                    format!("Field `{}` is mandatory.", std::stringify!(animations))
225                })?,
226                paused: self
227                    .paused
228                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(paused)))?,
229            },
230        })
231    }
232}
233impl SetPlaybackRate {
234    pub fn builder() -> SetPlaybackRateBuilder {
235        <SetPlaybackRateBuilder as Default>::default()
236    }
237}
238#[derive(Default, Clone)]
239pub struct SetPlaybackRateBuilder {
240    playback_rate: Option<f64>,
241}
242impl SetPlaybackRateBuilder {
243    pub fn playback_rate(mut self, playback_rate: impl Into<f64>) -> Self {
244        self.playback_rate = Some(playback_rate.into());
245        self
246    }
247    pub fn build(self) -> Result<SetPlaybackRate, String> {
248        Ok(SetPlaybackRate {
249            method: SetPlaybackRateMethod::SetPlaybackRate,
250            params: SetPlaybackRateParams {
251                playback_rate: self.playback_rate.ok_or_else(|| {
252                    format!("Field `{}` is mandatory.", std::stringify!(playback_rate))
253                })?,
254            },
255        })
256    }
257}
258impl SetTiming {
259    pub fn builder() -> SetTimingBuilder {
260        <SetTimingBuilder as Default>::default()
261    }
262}
263#[derive(Default, Clone)]
264pub struct SetTimingBuilder {
265    animation_id: Option<String>,
266    duration: Option<f64>,
267    delay: Option<f64>,
268}
269impl SetTimingBuilder {
270    pub fn animation_id(mut self, animation_id: impl Into<String>) -> Self {
271        self.animation_id = Some(animation_id.into());
272        self
273    }
274    pub fn duration(mut self, duration: impl Into<f64>) -> Self {
275        self.duration = Some(duration.into());
276        self
277    }
278    pub fn delay(mut self, delay: impl Into<f64>) -> Self {
279        self.delay = Some(delay.into());
280        self
281    }
282    pub fn build(self) -> Result<SetTiming, String> {
283        Ok(SetTiming {
284            method: SetTimingMethod::SetTiming,
285            params: SetTimingParams {
286                animation_id: self.animation_id.ok_or_else(|| {
287                    format!("Field `{}` is mandatory.", std::stringify!(animation_id))
288                })?,
289                duration: self.duration.ok_or_else(|| {
290                    format!("Field `{}` is mandatory.", std::stringify!(duration))
291                })?,
292                delay: self
293                    .delay
294                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(delay)))?,
295            },
296        })
297    }
298}