qubit_progress/model/progress_metric.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use serde::{
11 Deserialize,
12 Serialize,
13};
14
15/// Describes one metric dimension reported by a progress operation.
16///
17/// The `id` is stable and machine-readable. It is stored in
18/// [`ProgressCounter`](crate::ProgressCounter) values and therefore appears in
19/// JSON progress events. The `name` is human-readable and is intended for text
20/// reporters.
21#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
22pub struct ProgressMetric {
23 /// Stable machine-readable metric identifier.
24 id: String,
25 /// Human-readable metric name.
26 name: String,
27}
28
29impl ProgressMetric {
30 /// Creates a metric definition.
31 ///
32 /// # Parameters
33 ///
34 /// * `id` - Stable machine-readable metric identifier.
35 /// * `name` - Human-readable metric name.
36 ///
37 /// # Returns
38 ///
39 /// A metric definition with `id` and `name` recorded.
40 #[inline]
41 pub fn new(id: &str, name: &str) -> Self {
42 Self {
43 id: id.to_owned(),
44 name: name.to_owned(),
45 }
46 }
47
48 /// Returns the stable metric identifier.
49 ///
50 /// # Returns
51 ///
52 /// The machine-readable metric id.
53 #[inline]
54 pub fn id(&self) -> &str {
55 self.id.as_str()
56 }
57
58 /// Returns the human-readable metric name.
59 ///
60 /// # Returns
61 ///
62 /// The display name for this metric.
63 #[inline]
64 pub fn name(&self) -> &str {
65 self.name.as_str()
66 }
67}