Skip to main content

ferroui_dynamic_data/kernel/
item_with_value.rs

1//! `ItemWithValue<TObject, TValue>` (`Kernel/ItemWithValue.cs`).
2
3use std::fmt;
4
5/// An item and a value that goes with it (`ItemWithValue<TObject, TValue>`): equal when both
6/// parts are.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub struct ItemWithValue<T, V> {
9    item: T,
10    value: V,
11}
12
13impl<T, V> ItemWithValue<T, V> {
14    /// The pair (`ItemWithValue(TObject, TValue)`).
15    pub fn new(item: T, value: V) -> Self {
16        Self { item, value }
17    }
18
19    /// The item (`Item`).
20    pub fn item(&self) -> &T {
21        &self.item
22    }
23
24    /// The value (`Value`).
25    pub fn value(&self) -> &V {
26        &self.value
27    }
28
29    /// The item and the value.
30    pub fn into_parts(self) -> (T, V) {
31        (self.item, self.value)
32    }
33}
34
35impl<T: fmt::Display, V: fmt::Display> fmt::Display for ItemWithValue<T, V> {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        write!(f, "{} ({})", self.item, self.value)
38    }
39}