Skip to main content

metrickit/
call_stack_tree.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::error::MetricKitError;
5use crate::private::to_json_string;
6
7/// Rust representation of `MetricKit`'s `MXCallStackTree`.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(transparent)]
10pub struct CallStackTree(
11    /// Stores the raw JSON tree mirrored from `MXCallStackTree`.
12    pub Value,
13);
14
15impl CallStackTree {
16    /// Wraps a raw JSON value as an `MXCallStackTree` model.
17    #[must_use]
18    pub fn new(value: Value) -> Self {
19        Self(value)
20    }
21
22    /// Returns the raw JSON tree mirrored from `MXCallStackTree`.
23    #[must_use]
24    pub fn as_value(&self) -> &Value {
25        &self.0
26    }
27
28    /// Consumes this wrapper and returns the raw `MXCallStackTree` JSON.
29    #[must_use]
30    pub fn into_value(self) -> Value {
31        self.0
32    }
33
34    /// Returns the JSON representation of this `MXCallStackTree` model.
35    pub fn json_representation(&self) -> Result<String, MetricKitError> {
36        to_json_string(&self.0)
37    }
38}