yew_datatable_core/features/aggregation/aggregated_value.rs
1//! Aggregated value for a column in grouped rows.
2//!
3//! Represents the result of an aggregation operation on a column,
4//! storing the computed value and the function used to compute it.
5
6use crate::features::aggregation::built_in_aggregation::BuiltInAggregation;
7
8/// Aggregated value for a column.
9///
10/// Stores the string representation of an aggregated result
11/// along with the optional aggregation function used.
12#[derive(Debug, Clone, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct AggregatedValue {
15 /// The aggregated value as a string.
16 pub value: String,
17
18 /// The aggregation function used.
19 pub function: Option<BuiltInAggregation>,
20}
21
22impl AggregatedValue {
23 /// Creates a new aggregated value.
24 ///
25 /// # Parameters
26 ///
27 /// - `value`: The aggregated value string.
28 ///
29 /// # Returns
30 ///
31 /// - `AggregatedValue`: A new aggregated value without a function reference.
32 pub fn new(value: impl Into<String>) -> Self {
33 Self {
34 value: value.into(),
35 function: None,
36 }
37 }
38
39 /// Creates an aggregated value with a function reference.
40 ///
41 /// # Parameters
42 ///
43 /// - `value`: The aggregated value string.
44 /// - `function`: The aggregation function that produced this value.
45 ///
46 /// # Returns
47 ///
48 /// - `AggregatedValue`: A new aggregated value with a function reference.
49 pub fn with_function(value: impl Into<String>, function: BuiltInAggregation) -> Self {
50 Self {
51 value: value.into(),
52 function: Some(function),
53 }
54 }
55}