browser_protocol/performance/
mod.rs1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct Metric<'a> {
10 name: Cow<'a, str>,
12 value: f64,
14}
15
16impl<'a> Metric<'a> {
17 pub fn builder(name: impl Into<Cow<'a, str>>, value: f64) -> MetricBuilder<'a> {
18 MetricBuilder {
19 name: name.into(),
20 value: value,
21 }
22 }
23 pub fn name(&self) -> &str { self.name.as_ref() }
24 pub fn value(&self) -> f64 { self.value }
25}
26
27
28pub struct MetricBuilder<'a> {
29 name: Cow<'a, str>,
30 value: f64,
31}
32
33impl<'a> MetricBuilder<'a> {
34 pub fn build(self) -> Metric<'a> {
35 Metric {
36 name: self.name,
37 value: self.value,
38 }
39 }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43pub struct DisableParams {}
44
45impl DisableParams { pub const METHOD: &'static str = "Performance.disable"; }
46
47impl<'a> crate::CdpCommand<'a> for DisableParams {
48 const METHOD: &'static str = "Performance.disable";
49 type Response = crate::EmptyReturns;
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, Default)]
55#[serde(rename_all = "camelCase")]
56pub struct EnableParams<'a> {
57 #[serde(skip_serializing_if = "Option::is_none")]
59 timeDomain: Option<Cow<'a, str>>,
60}
61
62impl<'a> EnableParams<'a> {
63 pub fn builder() -> EnableParamsBuilder<'a> {
64 EnableParamsBuilder {
65 timeDomain: None,
66 }
67 }
68 pub fn timeDomain(&self) -> Option<&str> { self.timeDomain.as_deref() }
69}
70
71#[derive(Default)]
72pub struct EnableParamsBuilder<'a> {
73 timeDomain: Option<Cow<'a, str>>,
74}
75
76impl<'a> EnableParamsBuilder<'a> {
77 pub fn timeDomain(mut self, timeDomain: impl Into<Cow<'a, str>>) -> Self { self.timeDomain = Some(timeDomain.into()); self }
79 pub fn build(self) -> EnableParams<'a> {
80 EnableParams {
81 timeDomain: self.timeDomain,
82 }
83 }
84}
85
86impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "Performance.enable"; }
87
88impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
89 const METHOD: &'static str = "Performance.enable";
90 type Response = crate::EmptyReturns;
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize, Default)]
98#[serde(rename_all = "camelCase")]
99pub struct SetTimeDomainParams<'a> {
100 timeDomain: Cow<'a, str>,
102}
103
104impl<'a> SetTimeDomainParams<'a> {
105 pub fn builder(timeDomain: impl Into<Cow<'a, str>>) -> SetTimeDomainParamsBuilder<'a> {
106 SetTimeDomainParamsBuilder {
107 timeDomain: timeDomain.into(),
108 }
109 }
110 pub fn timeDomain(&self) -> &str { self.timeDomain.as_ref() }
111}
112
113
114pub struct SetTimeDomainParamsBuilder<'a> {
115 timeDomain: Cow<'a, str>,
116}
117
118impl<'a> SetTimeDomainParamsBuilder<'a> {
119 pub fn build(self) -> SetTimeDomainParams<'a> {
120 SetTimeDomainParams {
121 timeDomain: self.timeDomain,
122 }
123 }
124}
125
126impl<'a> SetTimeDomainParams<'a> { pub const METHOD: &'static str = "Performance.setTimeDomain"; }
127
128impl<'a> crate::CdpCommand<'a> for SetTimeDomainParams<'a> {
129 const METHOD: &'static str = "Performance.setTimeDomain";
130 type Response = crate::EmptyReturns;
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, Default)]
136#[serde(rename_all = "camelCase")]
137pub struct GetMetricsReturns<'a> {
138 metrics: Vec<Metric<'a>>,
140}
141
142impl<'a> GetMetricsReturns<'a> {
143 pub fn builder(metrics: Vec<Metric<'a>>) -> GetMetricsReturnsBuilder<'a> {
144 GetMetricsReturnsBuilder {
145 metrics: metrics,
146 }
147 }
148 pub fn metrics(&self) -> &[Metric<'a>] { &self.metrics }
149}
150
151
152pub struct GetMetricsReturnsBuilder<'a> {
153 metrics: Vec<Metric<'a>>,
154}
155
156impl<'a> GetMetricsReturnsBuilder<'a> {
157 pub fn build(self) -> GetMetricsReturns<'a> {
158 GetMetricsReturns {
159 metrics: self.metrics,
160 }
161 }
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
165pub struct GetMetricsParams {}
166
167impl GetMetricsParams { pub const METHOD: &'static str = "Performance.getMetrics"; }
168
169impl<'a> crate::CdpCommand<'a> for GetMetricsParams {
170 const METHOD: &'static str = "Performance.getMetrics";
171 type Response = GetMetricsReturns<'a>;
172}