linera_version/serde_pretty/
type.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct Pretty<T, Repr> {
6    pub value: T,
7    _phantom: std::marker::PhantomData<fn(Repr) -> Repr>,
8}
9
10impl<T, Repr> Pretty<T, Repr> {
11    pub const fn new(value: T) -> Self {
12        Pretty {
13            value,
14            _phantom: std::marker::PhantomData,
15        }
16    }
17
18    pub fn repr(self) -> Repr
19    where
20        Repr: From<T>,
21    {
22        Repr::from(self.value)
23    }
24}
25
26impl<T, Repr> std::fmt::Display for Pretty<T, Repr>
27where
28    T: Clone,
29    Repr: std::fmt::Display + From<T>,
30{
31    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
32        write!(formatter, "{}", Repr::from(self.value.clone()))
33    }
34}