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> {
21 MetricBuilder {
22 name: name.into(),
23 value: value,
24 }
25 }
26 pub fn name(&self) -> &str { self.name.as_ref() }
28 pub fn value(&self) -> f64 { self.value }
30}
31
32
33pub struct MetricBuilder<'a> {
34 name: Cow<'a, str>,
35 value: f64,
36}
37
38impl<'a> MetricBuilder<'a> {
39 pub fn build(self) -> Metric<'a> {
40 Metric {
41 name: self.name,
42 value: self.value,
43 }
44 }
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, Default)]
48pub struct DisableParams {}
49
50impl DisableParams { pub const METHOD: &'static str = "Performance.disable"; }
51
52impl<'a> crate::CdpCommand<'a> for DisableParams {
53 const METHOD: &'static str = "Performance.disable";
54 type Response = crate::EmptyReturns;
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, Default)]
60#[serde(rename_all = "camelCase")]
61pub struct EnableParams<'a> {
62 #[serde(skip_serializing_if = "Option::is_none", rename = "timeDomain")]
64 time_domain: Option<Cow<'a, str>>,
65}
66
67impl<'a> EnableParams<'a> {
68 pub fn builder() -> EnableParamsBuilder<'a> {
70 EnableParamsBuilder {
71 time_domain: None,
72 }
73 }
74 pub fn time_domain(&self) -> Option<&str> { self.time_domain.as_deref() }
76}
77
78#[derive(Default)]
79pub struct EnableParamsBuilder<'a> {
80 time_domain: Option<Cow<'a, str>>,
81}
82
83impl<'a> EnableParamsBuilder<'a> {
84 pub fn time_domain(mut self, time_domain: impl Into<Cow<'a, str>>) -> Self { self.time_domain = Some(time_domain.into()); self }
86 pub fn build(self) -> EnableParams<'a> {
87 EnableParams {
88 time_domain: self.time_domain,
89 }
90 }
91}
92
93impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "Performance.enable"; }
94
95impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
96 const METHOD: &'static str = "Performance.enable";
97 type Response = crate::EmptyReturns;
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, Default)]
105#[serde(rename_all = "camelCase")]
106pub struct SetTimeDomainParams<'a> {
107 #[serde(rename = "timeDomain")]
109 time_domain: Cow<'a, str>,
110}
111
112impl<'a> SetTimeDomainParams<'a> {
113 pub fn builder(time_domain: impl Into<Cow<'a, str>>) -> SetTimeDomainParamsBuilder<'a> {
116 SetTimeDomainParamsBuilder {
117 time_domain: time_domain.into(),
118 }
119 }
120 pub fn time_domain(&self) -> &str { self.time_domain.as_ref() }
122}
123
124
125pub struct SetTimeDomainParamsBuilder<'a> {
126 time_domain: Cow<'a, str>,
127}
128
129impl<'a> SetTimeDomainParamsBuilder<'a> {
130 pub fn build(self) -> SetTimeDomainParams<'a> {
131 SetTimeDomainParams {
132 time_domain: self.time_domain,
133 }
134 }
135}
136
137impl<'a> SetTimeDomainParams<'a> { pub const METHOD: &'static str = "Performance.setTimeDomain"; }
138
139impl<'a> crate::CdpCommand<'a> for SetTimeDomainParams<'a> {
140 const METHOD: &'static str = "Performance.setTimeDomain";
141 type Response = crate::EmptyReturns;
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize, Default)]
147#[serde(rename_all = "camelCase")]
148pub struct GetMetricsReturns<'a> {
149 metrics: Vec<Metric<'a>>,
151}
152
153impl<'a> GetMetricsReturns<'a> {
154 pub fn builder(metrics: Vec<Metric<'a>>) -> GetMetricsReturnsBuilder<'a> {
157 GetMetricsReturnsBuilder {
158 metrics: metrics,
159 }
160 }
161 pub fn metrics(&self) -> &[Metric<'a>] { &self.metrics }
163}
164
165
166pub struct GetMetricsReturnsBuilder<'a> {
167 metrics: Vec<Metric<'a>>,
168}
169
170impl<'a> GetMetricsReturnsBuilder<'a> {
171 pub fn build(self) -> GetMetricsReturns<'a> {
172 GetMetricsReturns {
173 metrics: self.metrics,
174 }
175 }
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize, Default)]
179pub struct GetMetricsParams {}
180
181impl GetMetricsParams { pub const METHOD: &'static str = "Performance.getMetrics"; }
182
183impl<'a> crate::CdpCommand<'a> for GetMetricsParams {
184 const METHOD: &'static str = "Performance.getMetrics";
185 type Response = GetMetricsReturns<'a>;
186}