1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use fmt;
use crateContext;
/// Create a displayable instance for a type.
///
/// # Usage:
///
/// For example, to display an `Option<i32>`, use `.display()` to create an instance that is
/// `Display`
///
/// ```
/// use to_display::ToDisplay;
/// assert_eq!(Some(1u32).display().to_string(), "1");
/// ```
///
/// If the returned type implements [`DisplayConfig`], it can be further customized with such
/// as:
/// - `.verbose()`: to enable verbose mode.
/// - `.max_items(n)`: display at most `n` items.
/// - ...
///
/// To implement [`ToDisplay`] for a type that implements `Display`, use `#[derive(ToDisplay)]`.
///
/// It displays an Option as `Some(value)` or `None`, if `verbose` is enabled.
/// and it displays an Option as `-` or `value`, if `verbose` is disabled.
///
/// It displays a Result as `Ok(value)` or `Err(error)`, if `verbose` is enabled.
///
/// It displays a slice as `[value1, value2, ...]`, if the number of items is less than or equal to
/// `max_items`.
///
/// [`DisplayConfig`]: crate::DisplayConfig