Skip to main content

rustenium_cdp_definitions/browser_protocol/background_service/
command_builders.rs

1use super::commands::*;
2impl StartObserving {
3    pub fn builder() -> StartObservingBuilder {
4        <StartObservingBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct StartObservingBuilder {
9    service: Option<super::types::ServiceName>,
10}
11impl StartObservingBuilder {
12    pub fn service(mut self, service: impl Into<super::types::ServiceName>) -> Self {
13        self.service = Some(service.into());
14        self
15    }
16    pub fn build(self) -> Result<StartObserving, String> {
17        Ok(StartObserving {
18            method: StartObservingMethod::StartObserving,
19            params: StartObservingParams {
20                service: self
21                    .service
22                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(service)))?,
23            },
24        })
25    }
26}
27impl StopObserving {
28    pub fn builder() -> StopObservingBuilder {
29        <StopObservingBuilder as Default>::default()
30    }
31}
32#[derive(Default, Clone)]
33pub struct StopObservingBuilder {
34    service: Option<super::types::ServiceName>,
35}
36impl StopObservingBuilder {
37    pub fn service(mut self, service: impl Into<super::types::ServiceName>) -> Self {
38        self.service = Some(service.into());
39        self
40    }
41    pub fn build(self) -> Result<StopObserving, String> {
42        Ok(StopObserving {
43            method: StopObservingMethod::StopObserving,
44            params: StopObservingParams {
45                service: self
46                    .service
47                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(service)))?,
48            },
49        })
50    }
51}
52impl SetRecording {
53    pub fn builder() -> SetRecordingBuilder {
54        <SetRecordingBuilder as Default>::default()
55    }
56}
57#[derive(Default, Clone)]
58pub struct SetRecordingBuilder {
59    should_record: Option<bool>,
60    service: Option<super::types::ServiceName>,
61}
62impl SetRecordingBuilder {
63    pub fn should_record(mut self, should_record: impl Into<bool>) -> Self {
64        self.should_record = Some(should_record.into());
65        self
66    }
67    pub fn service(mut self, service: impl Into<super::types::ServiceName>) -> Self {
68        self.service = Some(service.into());
69        self
70    }
71    pub fn build(self) -> Result<SetRecording, String> {
72        Ok(SetRecording {
73            method: SetRecordingMethod::SetRecording,
74            params: SetRecordingParams {
75                should_record: self.should_record.ok_or_else(|| {
76                    format!("Field `{}` is mandatory.", std::stringify!(should_record))
77                })?,
78                service: self
79                    .service
80                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(service)))?,
81            },
82        })
83    }
84}
85impl ClearEvents {
86    pub fn builder() -> ClearEventsBuilder {
87        <ClearEventsBuilder as Default>::default()
88    }
89}
90#[derive(Default, Clone)]
91pub struct ClearEventsBuilder {
92    service: Option<super::types::ServiceName>,
93}
94impl ClearEventsBuilder {
95    pub fn service(mut self, service: impl Into<super::types::ServiceName>) -> Self {
96        self.service = Some(service.into());
97        self
98    }
99    pub fn build(self) -> Result<ClearEvents, String> {
100        Ok(ClearEvents {
101            method: ClearEventsMethod::ClearEvents,
102            params: ClearEventsParams {
103                service: self
104                    .service
105                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(service)))?,
106            },
107        })
108    }
109}