Skip to main content

rustenium_cdp_definitions/js_protocol/heap_profiler/
command_builders.rs

1use super::commands::*;
2impl AddInspectedHeapObject {
3    pub fn builder() -> AddInspectedHeapObjectBuilder {
4        <AddInspectedHeapObjectBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct AddInspectedHeapObjectBuilder {
9    heap_object_id: Option<super::types::HeapSnapshotObjectId>,
10}
11impl AddInspectedHeapObjectBuilder {
12    pub fn heap_object_id(
13        mut self,
14        heap_object_id: impl Into<super::types::HeapSnapshotObjectId>,
15    ) -> Self {
16        self.heap_object_id = Some(heap_object_id.into());
17        self
18    }
19    pub fn build(self) -> Result<AddInspectedHeapObject, String> {
20        Ok(AddInspectedHeapObject {
21            method: AddInspectedHeapObjectMethod::AddInspectedHeapObject,
22            params: AddInspectedHeapObjectParams {
23                heap_object_id: self.heap_object_id.ok_or_else(|| {
24                    format!("Field `{}` is mandatory.", std::stringify!(heap_object_id))
25                })?,
26            },
27        })
28    }
29}
30#[derive(Debug, Clone, Default)]
31pub struct CollectGarbageBuilder;
32impl CollectGarbageBuilder {
33    pub fn new() -> Self {
34        Self
35    }
36    pub fn build(self) -> CollectGarbage {
37        CollectGarbage {
38            method: CollectGarbageMethod::CollectGarbage,
39            params: CollectGarbageParams {},
40        }
41    }
42}
43impl CollectGarbage {
44    pub fn builder() -> CollectGarbageBuilder {
45        CollectGarbageBuilder
46    }
47}
48#[derive(Debug, Clone, Default)]
49pub struct DisableBuilder;
50impl DisableBuilder {
51    pub fn new() -> Self {
52        Self
53    }
54    pub fn build(self) -> Disable {
55        Disable {
56            method: DisableMethod::Disable,
57            params: DisableParams {},
58        }
59    }
60}
61impl Disable {
62    pub fn builder() -> DisableBuilder {
63        DisableBuilder
64    }
65}
66#[derive(Debug, Clone, Default)]
67pub struct EnableBuilder;
68impl EnableBuilder {
69    pub fn new() -> Self {
70        Self
71    }
72    pub fn build(self) -> Enable {
73        Enable {
74            method: EnableMethod::Enable,
75            params: EnableParams {},
76        }
77    }
78}
79impl Enable {
80    pub fn builder() -> EnableBuilder {
81        EnableBuilder
82    }
83}
84impl GetHeapObjectId {
85    pub fn builder() -> GetHeapObjectIdBuilder {
86        <GetHeapObjectIdBuilder as Default>::default()
87    }
88}
89#[derive(Default, Clone)]
90pub struct GetHeapObjectIdBuilder {
91    object_id: Option<crate::js_protocol::runtime::types::RemoteObjectId>,
92}
93impl GetHeapObjectIdBuilder {
94    pub fn object_id(
95        mut self,
96        object_id: impl Into<crate::js_protocol::runtime::types::RemoteObjectId>,
97    ) -> Self {
98        self.object_id = Some(object_id.into());
99        self
100    }
101    pub fn build(self) -> Result<GetHeapObjectId, String> {
102        Ok(GetHeapObjectId {
103            method: GetHeapObjectIdMethod::GetHeapObjectId,
104            params: GetHeapObjectIdParams {
105                object_id: self.object_id.ok_or_else(|| {
106                    format!("Field `{}` is mandatory.", std::stringify!(object_id))
107                })?,
108            },
109        })
110    }
111}
112impl GetObjectByHeapObjectId {
113    pub fn builder() -> GetObjectByHeapObjectIdBuilder {
114        <GetObjectByHeapObjectIdBuilder as Default>::default()
115    }
116}
117#[derive(Default, Clone)]
118pub struct GetObjectByHeapObjectIdBuilder {
119    object_id: Option<super::types::HeapSnapshotObjectId>,
120    object_group: Option<String>,
121}
122impl GetObjectByHeapObjectIdBuilder {
123    pub fn object_id(mut self, object_id: impl Into<super::types::HeapSnapshotObjectId>) -> Self {
124        self.object_id = Some(object_id.into());
125        self
126    }
127    pub fn object_group(mut self, object_group: impl Into<String>) -> Self {
128        self.object_group = Some(object_group.into());
129        self
130    }
131    pub fn build(self) -> Result<GetObjectByHeapObjectId, String> {
132        Ok(GetObjectByHeapObjectId {
133            method: GetObjectByHeapObjectIdMethod::GetObjectByHeapObjectId,
134            params: GetObjectByHeapObjectIdParams {
135                object_id: self.object_id.ok_or_else(|| {
136                    format!("Field `{}` is mandatory.", std::stringify!(object_id))
137                })?,
138                object_group: self.object_group,
139            },
140        })
141    }
142}
143#[derive(Debug, Clone, Default)]
144pub struct GetSamplingProfileBuilder;
145impl GetSamplingProfileBuilder {
146    pub fn new() -> Self {
147        Self
148    }
149    pub fn build(self) -> GetSamplingProfile {
150        GetSamplingProfile {
151            method: GetSamplingProfileMethod::GetSamplingProfile,
152            params: GetSamplingProfileParams {},
153        }
154    }
155}
156impl GetSamplingProfile {
157    pub fn builder() -> GetSamplingProfileBuilder {
158        GetSamplingProfileBuilder
159    }
160}
161impl StartSampling {
162    pub fn builder() -> StartSamplingBuilder {
163        <StartSamplingBuilder as Default>::default()
164    }
165}
166#[derive(Default, Clone)]
167pub struct StartSamplingBuilder {
168    sampling_interval: Option<f64>,
169    stack_depth: Option<f64>,
170    include_objects_collected_by_major_gc: Option<bool>,
171    include_objects_collected_by_minor_gc: Option<bool>,
172}
173impl StartSamplingBuilder {
174    pub fn sampling_interval(mut self, sampling_interval: impl Into<f64>) -> Self {
175        self.sampling_interval = Some(sampling_interval.into());
176        self
177    }
178    pub fn stack_depth(mut self, stack_depth: impl Into<f64>) -> Self {
179        self.stack_depth = Some(stack_depth.into());
180        self
181    }
182    pub fn include_objects_collected_by_major_gc(
183        mut self,
184        include_objects_collected_by_major_gc: impl Into<bool>,
185    ) -> Self {
186        self.include_objects_collected_by_major_gc =
187            Some(include_objects_collected_by_major_gc.into());
188        self
189    }
190    pub fn include_objects_collected_by_minor_gc(
191        mut self,
192        include_objects_collected_by_minor_gc: impl Into<bool>,
193    ) -> Self {
194        self.include_objects_collected_by_minor_gc =
195            Some(include_objects_collected_by_minor_gc.into());
196        self
197    }
198    pub fn build(self) -> StartSampling {
199        StartSampling {
200            method: StartSamplingMethod::StartSampling,
201            params: StartSamplingParams {
202                sampling_interval: self.sampling_interval,
203                stack_depth: self.stack_depth,
204                include_objects_collected_by_major_gc: self.include_objects_collected_by_major_gc,
205                include_objects_collected_by_minor_gc: self.include_objects_collected_by_minor_gc,
206            },
207        }
208    }
209}
210impl StartTrackingHeapObjects {
211    pub fn builder() -> StartTrackingHeapObjectsBuilder {
212        <StartTrackingHeapObjectsBuilder as Default>::default()
213    }
214}
215#[derive(Default, Clone)]
216pub struct StartTrackingHeapObjectsBuilder {
217    track_allocations: Option<bool>,
218}
219impl StartTrackingHeapObjectsBuilder {
220    pub fn track_allocations(mut self, track_allocations: impl Into<bool>) -> Self {
221        self.track_allocations = Some(track_allocations.into());
222        self
223    }
224    pub fn build(self) -> StartTrackingHeapObjects {
225        StartTrackingHeapObjects {
226            method: StartTrackingHeapObjectsMethod::StartTrackingHeapObjects,
227            params: StartTrackingHeapObjectsParams {
228                track_allocations: self.track_allocations,
229            },
230        }
231    }
232}
233#[derive(Debug, Clone, Default)]
234pub struct StopSamplingBuilder;
235impl StopSamplingBuilder {
236    pub fn new() -> Self {
237        Self
238    }
239    pub fn build(self) -> StopSampling {
240        StopSampling {
241            method: StopSamplingMethod::StopSampling,
242            params: StopSamplingParams {},
243        }
244    }
245}
246impl StopSampling {
247    pub fn builder() -> StopSamplingBuilder {
248        StopSamplingBuilder
249    }
250}
251impl StopTrackingHeapObjects {
252    pub fn builder() -> StopTrackingHeapObjectsBuilder {
253        <StopTrackingHeapObjectsBuilder as Default>::default()
254    }
255}
256#[derive(Default, Clone)]
257pub struct StopTrackingHeapObjectsBuilder {
258    report_progress: Option<bool>,
259    capture_numeric_value: Option<bool>,
260    expose_internals: Option<bool>,
261}
262impl StopTrackingHeapObjectsBuilder {
263    pub fn report_progress(mut self, report_progress: impl Into<bool>) -> Self {
264        self.report_progress = Some(report_progress.into());
265        self
266    }
267    pub fn capture_numeric_value(mut self, capture_numeric_value: impl Into<bool>) -> Self {
268        self.capture_numeric_value = Some(capture_numeric_value.into());
269        self
270    }
271    pub fn expose_internals(mut self, expose_internals: impl Into<bool>) -> Self {
272        self.expose_internals = Some(expose_internals.into());
273        self
274    }
275    pub fn build(self) -> StopTrackingHeapObjects {
276        StopTrackingHeapObjects {
277            method: StopTrackingHeapObjectsMethod::StopTrackingHeapObjects,
278            params: StopTrackingHeapObjectsParams {
279                report_progress: self.report_progress,
280                capture_numeric_value: self.capture_numeric_value,
281                expose_internals: self.expose_internals,
282            },
283        }
284    }
285}
286impl TakeHeapSnapshot {
287    pub fn builder() -> TakeHeapSnapshotBuilder {
288        <TakeHeapSnapshotBuilder as Default>::default()
289    }
290}
291#[derive(Default, Clone)]
292pub struct TakeHeapSnapshotBuilder {
293    report_progress: Option<bool>,
294    capture_numeric_value: Option<bool>,
295    expose_internals: Option<bool>,
296}
297impl TakeHeapSnapshotBuilder {
298    pub fn report_progress(mut self, report_progress: impl Into<bool>) -> Self {
299        self.report_progress = Some(report_progress.into());
300        self
301    }
302    pub fn capture_numeric_value(mut self, capture_numeric_value: impl Into<bool>) -> Self {
303        self.capture_numeric_value = Some(capture_numeric_value.into());
304        self
305    }
306    pub fn expose_internals(mut self, expose_internals: impl Into<bool>) -> Self {
307        self.expose_internals = Some(expose_internals.into());
308        self
309    }
310    pub fn build(self) -> TakeHeapSnapshot {
311        TakeHeapSnapshot {
312            method: TakeHeapSnapshotMethod::TakeHeapSnapshot,
313            params: TakeHeapSnapshotParams {
314                report_progress: self.report_progress,
315                capture_numeric_value: self.capture_numeric_value,
316                expose_internals: self.expose_internals,
317            },
318        }
319    }
320}