Skip to main content

rustenium_cdp_definitions/browser_protocol/autofill/
command_builders.rs

1use super::commands::*;
2impl Trigger {
3    pub fn builder() -> TriggerBuilder {
4        <TriggerBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct TriggerBuilder {
9    field_id: Option<crate::browser_protocol::dom::types::BackendNodeId>,
10    frame_id: Option<crate::browser_protocol::page::types::FrameId>,
11    card: Option<super::types::CreditCard>,
12    address: Option<super::types::Address>,
13}
14impl TriggerBuilder {
15    pub fn field_id(
16        mut self,
17        field_id: impl Into<crate::browser_protocol::dom::types::BackendNodeId>,
18    ) -> Self {
19        self.field_id = Some(field_id.into());
20        self
21    }
22    pub fn frame_id(
23        mut self,
24        frame_id: impl Into<crate::browser_protocol::page::types::FrameId>,
25    ) -> Self {
26        self.frame_id = Some(frame_id.into());
27        self
28    }
29    pub fn card(mut self, card: impl Into<super::types::CreditCard>) -> Self {
30        self.card = Some(card.into());
31        self
32    }
33    pub fn address(mut self, address: impl Into<super::types::Address>) -> Self {
34        self.address = Some(address.into());
35        self
36    }
37    pub fn build(self) -> Result<Trigger, String> {
38        Ok(Trigger {
39            method: TriggerMethod::Trigger,
40            params: TriggerParams {
41                field_id: self.field_id.ok_or_else(|| {
42                    format!("Field `{}` is mandatory.", std::stringify!(field_id))
43                })?,
44                frame_id: self.frame_id,
45                card: self.card,
46                address: self.address,
47            },
48        })
49    }
50}
51impl SetAddresses {
52    pub fn builder() -> SetAddressesBuilder {
53        <SetAddressesBuilder as Default>::default()
54    }
55}
56#[derive(Default, Clone)]
57pub struct SetAddressesBuilder {
58    addresses: Option<Vec<super::types::Address>>,
59}
60impl SetAddressesBuilder {
61    pub fn addresse(mut self, addresse: impl Into<super::types::Address>) -> Self {
62        let v = self.addresses.get_or_insert(Vec::new());
63        v.push(addresse.into());
64        self
65    }
66    pub fn addresses<I, S>(mut self, addresses: I) -> Self
67    where
68        I: IntoIterator<Item = S>,
69        S: Into<super::types::Address>,
70    {
71        let v = self.addresses.get_or_insert(Vec::new());
72        for val in addresses {
73            v.push(val.into());
74        }
75        self
76    }
77    pub fn build(self) -> Result<SetAddresses, String> {
78        Ok(SetAddresses {
79            method: SetAddressesMethod::SetAddresses,
80            params: SetAddressesParams {
81                addresses: self.addresses.ok_or_else(|| {
82                    format!("Field `{}` is mandatory.", std::stringify!(addresses))
83                })?,
84            },
85        })
86    }
87}
88#[derive(Debug, Clone, Default)]
89pub struct DisableBuilder;
90impl DisableBuilder {
91    pub fn new() -> Self {
92        Self
93    }
94    pub fn build(self) -> Disable {
95        Disable {
96            method: DisableMethod::Disable,
97            params: DisableParams {},
98        }
99    }
100}
101impl Disable {
102    pub fn builder() -> DisableBuilder {
103        DisableBuilder
104    }
105}
106#[derive(Debug, Clone, Default)]
107pub struct EnableBuilder;
108impl EnableBuilder {
109    pub fn new() -> Self {
110        Self
111    }
112    pub fn build(self) -> Enable {
113        Enable {
114            method: EnableMethod::Enable,
115            params: EnableParams {},
116        }
117    }
118}
119impl Enable {
120    pub fn builder() -> EnableBuilder {
121        EnableBuilder
122    }
123}