rustenium_bidi_definitions/browser/
command_builders.rs1use super::commands::*;
2#[derive(Debug, Clone, Default)]
3pub struct CloseBuilder;
4impl CloseBuilder {
5 pub fn new() -> Self {
6 Self
7 }
8 pub fn build(self) -> Close {
9 Close {
10 method: CloseMethod::Close,
11 params: CloseParams {},
12 }
13 }
14}
15impl Close {
16 pub fn builder() -> CloseBuilder {
17 CloseBuilder
18 }
19}
20impl CreateUserContext {
21 pub fn builder() -> CreateUserContextBuilder {
22 <CreateUserContextBuilder as Default>::default()
23 }
24}
25#[derive(Default, Clone)]
26pub struct CreateUserContextBuilder {
27 accept_insecure_certs: Option<bool>,
28 proxy: Option<crate::session::types::ProxyConfiguration>,
29 unhandled_prompt_behavior: Option<crate::session::types::UserPromptHandler>,
30}
31impl CreateUserContextBuilder {
32 pub fn accept_insecure_certs(mut self, accept_insecure_certs: impl Into<bool>) -> Self {
33 self.accept_insecure_certs = Some(accept_insecure_certs.into());
34 self
35 }
36 pub fn proxy(mut self, proxy: impl Into<crate::session::types::ProxyConfiguration>) -> Self {
37 self.proxy = Some(proxy.into());
38 self
39 }
40 pub fn unhandled_prompt_behavior(
41 mut self,
42 unhandled_prompt_behavior: impl Into<crate::session::types::UserPromptHandler>,
43 ) -> Self {
44 self.unhandled_prompt_behavior = Some(unhandled_prompt_behavior.into());
45 self
46 }
47 pub fn build(self) -> CreateUserContext {
48 CreateUserContext {
49 method: CreateUserContextMethod::CreateUserContext,
50 params: CreateUserContextParams {
51 accept_insecure_certs: self.accept_insecure_certs,
52 proxy: self.proxy,
53 unhandled_prompt_behavior: self.unhandled_prompt_behavior,
54 },
55 }
56 }
57}
58#[derive(Debug, Clone, Default)]
59pub struct GetClientWindowsBuilder;
60impl GetClientWindowsBuilder {
61 pub fn new() -> Self {
62 Self
63 }
64 pub fn build(self) -> GetClientWindows {
65 GetClientWindows {
66 method: GetClientWindowsMethod::GetClientWindows,
67 params: GetClientWindowsParams {},
68 }
69 }
70}
71impl GetClientWindows {
72 pub fn builder() -> GetClientWindowsBuilder {
73 GetClientWindowsBuilder
74 }
75}
76#[derive(Debug, Clone, Default)]
77pub struct GetUserContextsBuilder;
78impl GetUserContextsBuilder {
79 pub fn new() -> Self {
80 Self
81 }
82 pub fn build(self) -> GetUserContexts {
83 GetUserContexts {
84 method: GetUserContextsMethod::GetUserContexts,
85 params: GetUserContextsParams {},
86 }
87 }
88}
89impl GetUserContexts {
90 pub fn builder() -> GetUserContextsBuilder {
91 GetUserContextsBuilder
92 }
93}
94impl RemoveUserContext {
95 pub fn builder() -> RemoveUserContextBuilder {
96 <RemoveUserContextBuilder as Default>::default()
97 }
98}
99#[derive(Default, Clone)]
100pub struct RemoveUserContextBuilder {
101 user_context: Option<super::types::UserContext>,
102}
103impl RemoveUserContextBuilder {
104 pub fn user_context(mut self, user_context: impl Into<super::types::UserContext>) -> Self {
105 self.user_context = Some(user_context.into());
106 self
107 }
108 pub fn build(self) -> Result<RemoveUserContext, String> {
109 Ok(RemoveUserContext {
110 method: RemoveUserContextMethod::RemoveUserContext,
111 params: RemoveUserContextParams {
112 user_context: self.user_context.ok_or_else(|| {
113 format!("Field `{}` is mandatory.", std::stringify!(user_context))
114 })?,
115 },
116 })
117 }
118}
119impl SetClientWindowState {
120 pub fn builder() -> SetClientWindowStateBuilder {
121 <SetClientWindowStateBuilder as Default>::default()
122 }
123}
124#[derive(Default, Clone)]
125pub struct SetClientWindowStateBuilder {
126 client_window: Option<super::types::ClientWindow>,
127 client_window_named_state_client_window_rect_state_union:
128 Option<super::types::ClientWindowNamedStateClientWindowRectStateUnion>,
129}
130impl SetClientWindowStateBuilder {
131 pub fn client_window(mut self, client_window: impl Into<super::types::ClientWindow>) -> Self {
132 self.client_window = Some(client_window.into());
133 self
134 }
135 pub fn client_window_named_state_client_window_rect_state_union(
136 mut self,
137 client_window_named_state_client_window_rect_state_union: impl Into<
138 super::types::ClientWindowNamedStateClientWindowRectStateUnion,
139 >,
140 ) -> Self {
141 self.client_window_named_state_client_window_rect_state_union =
142 Some(client_window_named_state_client_window_rect_state_union.into());
143 self
144 }
145 pub fn build(self) -> Result<SetClientWindowState, String> {
146 Ok(SetClientWindowState {
147 method: SetClientWindowStateMethod::SetClientWindowState,
148 params: SetClientWindowStateParams {
149 client_window: self.client_window.ok_or_else(|| {
150 format!("Field `{}` is mandatory.", std::stringify!(client_window))
151 })?,
152 client_window_named_state_client_window_rect_state_union: self
153 .client_window_named_state_client_window_rect_state_union
154 .ok_or_else(|| {
155 format!(
156 "Field `{}` is mandatory.",
157 std::stringify!(
158 client_window_named_state_client_window_rect_state_union
159 )
160 )
161 })?,
162 },
163 })
164 }
165}
166impl SetDownloadBehavior {
167 pub fn builder() -> SetDownloadBehaviorBuilder {
168 <SetDownloadBehaviorBuilder as Default>::default()
169 }
170}
171#[derive(Default, Clone)]
172pub struct SetDownloadBehaviorBuilder {
173 download_behavior: Option<super::types::DownloadBehavior>,
174 user_contexts: Option<Vec<super::types::UserContext>>,
175}
176impl SetDownloadBehaviorBuilder {
177 pub fn download_behavior(
178 mut self,
179 download_behavior: impl Into<super::types::DownloadBehavior>,
180 ) -> Self {
181 self.download_behavior = Some(download_behavior.into());
182 self
183 }
184 pub fn user_context(mut self, user_context: impl Into<super::types::UserContext>) -> Self {
185 let v = self.user_contexts.get_or_insert(Vec::new());
186 v.push(user_context.into());
187 self
188 }
189 pub fn user_contexts<I, S>(mut self, user_contexts: I) -> Self
190 where
191 I: IntoIterator<Item = S>,
192 S: Into<super::types::UserContext>,
193 {
194 let v = self.user_contexts.get_or_insert(Vec::new());
195 for val in user_contexts {
196 v.push(val.into());
197 }
198 self
199 }
200 pub fn build(self) -> SetDownloadBehavior {
201 SetDownloadBehavior {
202 method: SetDownloadBehaviorMethod::SetDownloadBehavior,
203 params: SetDownloadBehaviorParams {
204 download_behavior: self.download_behavior,
205 user_contexts: self.user_contexts,
206 },
207 }
208 }
209}