rustenium_bidi_definitions/input/
command_builders.rs1use super::commands::*;
2impl PerformActions {
3 pub fn builder() -> PerformActionsBuilder {
4 <PerformActionsBuilder as Default>::default()
5 }
6}
7#[derive(Default, Clone)]
8pub struct PerformActionsBuilder {
9 context: Option<crate::browsing_context::types::BrowsingContext>,
10 actions: Option<Vec<super::types::SourceActions>>,
11}
12impl PerformActionsBuilder {
13 pub fn context(
14 mut self,
15 context: impl Into<crate::browsing_context::types::BrowsingContext>,
16 ) -> Self {
17 self.context = Some(context.into());
18 self
19 }
20 pub fn action(mut self, action: impl Into<super::types::SourceActions>) -> Self {
21 let v = self.actions.get_or_insert(Vec::new());
22 v.push(action.into());
23 self
24 }
25 pub fn actions<I, S>(mut self, actions: I) -> Self
26 where
27 I: IntoIterator<Item = S>,
28 S: Into<super::types::SourceActions>,
29 {
30 let v = self.actions.get_or_insert(Vec::new());
31 for val in actions {
32 v.push(val.into());
33 }
34 self
35 }
36 pub fn build(self) -> Result<PerformActions, String> {
37 Ok(PerformActions {
38 method: PerformActionsMethod::PerformActions,
39 params: PerformActionsParams {
40 context: self
41 .context
42 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
43 actions: self
44 .actions
45 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(actions)))?,
46 },
47 })
48 }
49}
50impl ReleaseActions {
51 pub fn builder() -> ReleaseActionsBuilder {
52 <ReleaseActionsBuilder as Default>::default()
53 }
54}
55#[derive(Default, Clone)]
56pub struct ReleaseActionsBuilder {
57 context: Option<crate::browsing_context::types::BrowsingContext>,
58}
59impl ReleaseActionsBuilder {
60 pub fn context(
61 mut self,
62 context: impl Into<crate::browsing_context::types::BrowsingContext>,
63 ) -> Self {
64 self.context = Some(context.into());
65 self
66 }
67 pub fn build(self) -> Result<ReleaseActions, String> {
68 Ok(ReleaseActions {
69 method: ReleaseActionsMethod::ReleaseActions,
70 params: ReleaseActionsParams {
71 context: self
72 .context
73 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
74 },
75 })
76 }
77}
78impl SetFiles {
79 pub fn builder() -> SetFilesBuilder {
80 <SetFilesBuilder as Default>::default()
81 }
82}
83#[derive(Default, Clone)]
84pub struct SetFilesBuilder {
85 context: Option<crate::browsing_context::types::BrowsingContext>,
86 element: Option<crate::script::types::SharedReference>,
87 files: Option<Vec<String>>,
88}
89impl SetFilesBuilder {
90 pub fn context(
91 mut self,
92 context: impl Into<crate::browsing_context::types::BrowsingContext>,
93 ) -> Self {
94 self.context = Some(context.into());
95 self
96 }
97 pub fn element(mut self, element: impl Into<crate::script::types::SharedReference>) -> Self {
98 self.element = Some(element.into());
99 self
100 }
101 pub fn file(mut self, file: impl Into<String>) -> Self {
102 let v = self.files.get_or_insert(Vec::new());
103 v.push(file.into());
104 self
105 }
106 pub fn files<I, S>(mut self, files: I) -> Self
107 where
108 I: IntoIterator<Item = S>,
109 S: Into<String>,
110 {
111 let v = self.files.get_or_insert(Vec::new());
112 for val in files {
113 v.push(val.into());
114 }
115 self
116 }
117 pub fn build(self) -> Result<SetFiles, String> {
118 Ok(SetFiles {
119 method: SetFilesMethod::SetFiles,
120 params: SetFilesParams {
121 context: self
122 .context
123 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(context)))?,
124 element: self
125 .element
126 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(element)))?,
127 files: self
128 .files
129 .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(files)))?,
130 },
131 })
132 }
133}