sbor/representations/
traits.rs

1use crate::rust::prelude::*;
2use crate::traversal::*;
3use crate::*;
4
5pub trait CustomDisplayContext<'a>: Default + Copy {
6    type CustomExtension: FormattableCustomExtension<CustomDisplayContext<'a> = Self>;
7}
8
9pub trait FormattableCustomExtension: CustomExtension + Copy {
10    type CustomDisplayContext<'a>: CustomDisplayContext<'a>;
11
12    /// The gives the inner formatted representation of the value.
13    /// This function should write the value content to the formatter.
14    ///
15    /// * The rust-like representation is as a newtype: CustomValueKind(<value_content>)
16    /// * The nested string representation is identical: CustomValueKind(<value_content>)
17    fn display_string_content<'s, 'de, 'a, 't, 's1, 's2, F: fmt::Write>(
18        f: &mut F,
19        context: &Self::CustomDisplayContext<'a>,
20        value: &<Self::CustomTraversal as CustomTraversal>::CustomTerminalValueRef<'de>,
21    ) -> Result<(), fmt::Error>;
22
23    /// This should output code to generate the value.
24    fn code_generation_string_content<'s, 'de, 'a, 't, 's1, 's2, F: fmt::Write>(
25        f: &mut F,
26        context: &Self::CustomDisplayContext<'a>,
27        value: &<Self::CustomTraversal as CustomTraversal>::CustomTerminalValueRef<'de>,
28    ) -> Result<(), fmt::Error>;
29
30    /// The gives the inner debug representation of the value.
31    /// This function should write the value content to the formatter.
32    ///
33    /// If overriden, this should be a more concise representation than [`display_string_content`].
34    ///
35    /// [`display_string_content`]: [FormattableCustomExtension::display_string_content]
36    fn debug_string_content<'s, 'de, 'a, 't, 's1, 's2, F: fmt::Write>(
37        f: &mut F,
38        context: &Self::CustomDisplayContext<'a>,
39        value: &<Self::CustomTraversal as CustomTraversal>::CustomTerminalValueRef<'de>,
40    ) -> Result<(), fmt::Error> {
41        Self::display_string_content(f, context, value)
42    }
43}