Skip to main content

rustenium_cdp_definitions/browser_protocol/device_orientation/
command_builders.rs

1use super::commands::*;
2#[derive(Debug, Clone, Default)]
3pub struct ClearDeviceOrientationOverrideBuilder;
4impl ClearDeviceOrientationOverrideBuilder {
5    pub fn new() -> Self {
6        Self
7    }
8    pub fn build(self) -> ClearDeviceOrientationOverride {
9        ClearDeviceOrientationOverride {
10            method: ClearDeviceOrientationOverrideMethod::ClearDeviceOrientationOverride,
11            params: ClearDeviceOrientationOverrideParams {},
12        }
13    }
14}
15impl ClearDeviceOrientationOverride {
16    pub fn builder() -> ClearDeviceOrientationOverrideBuilder {
17        ClearDeviceOrientationOverrideBuilder
18    }
19}
20impl SetDeviceOrientationOverride {
21    pub fn builder() -> SetDeviceOrientationOverrideBuilder {
22        <SetDeviceOrientationOverrideBuilder as Default>::default()
23    }
24}
25#[derive(Default, Clone)]
26pub struct SetDeviceOrientationOverrideBuilder {
27    alpha: Option<f64>,
28    beta: Option<f64>,
29    gamma: Option<f64>,
30}
31impl SetDeviceOrientationOverrideBuilder {
32    pub fn alpha(mut self, alpha: impl Into<f64>) -> Self {
33        self.alpha = Some(alpha.into());
34        self
35    }
36    pub fn beta(mut self, beta: impl Into<f64>) -> Self {
37        self.beta = Some(beta.into());
38        self
39    }
40    pub fn gamma(mut self, gamma: impl Into<f64>) -> Self {
41        self.gamma = Some(gamma.into());
42        self
43    }
44    pub fn build(self) -> Result<SetDeviceOrientationOverride, String> {
45        Ok(SetDeviceOrientationOverride {
46            method: SetDeviceOrientationOverrideMethod::SetDeviceOrientationOverride,
47            params: SetDeviceOrientationOverrideParams {
48                alpha: self
49                    .alpha
50                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(alpha)))?,
51                beta: self
52                    .beta
53                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(beta)))?,
54                gamma: self
55                    .gamma
56                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(gamma)))?,
57            },
58        })
59    }
60}