Skip to main content

ptx_parser/pretty_print/
primitives.rs

1use super::tree_formatter::truncate_with_ellipsis;
2use super::{TreeDisplay, TreeFormatter};
3/// TreeDisplay implementations for primitive types that commonly appear in the AST.
4use std::fmt;
5
6impl TreeDisplay for String {
7    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
8        f.root(&format!("String: \"{}\"", truncate_with_ellipsis(self, 40)))
9    }
10}
11
12impl TreeDisplay for bool {
13    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
14        f.root(&format!("bool: {}", self))
15    }
16}
17
18impl TreeDisplay for u8 {
19    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
20        f.root(&format!("u8: {}", self))
21    }
22}
23
24impl TreeDisplay for u16 {
25    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
26        f.root(&format!("u16: {}", self))
27    }
28}
29
30impl TreeDisplay for u32 {
31    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
32        f.root(&format!("u32: {}", self))
33    }
34}
35
36impl TreeDisplay for u64 {
37    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
38        f.root(&format!("u64: {}", self))
39    }
40}
41
42impl TreeDisplay for i16 {
43    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
44        f.root(&format!("i16: {}", self))
45    }
46}
47
48impl TreeDisplay for i32 {
49    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
50        f.root(&format!("i32: {}", self))
51    }
52}
53
54impl TreeDisplay for i64 {
55    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
56        f.root(&format!("i64: {}", self))
57    }
58}
59
60impl TreeDisplay for i128 {
61    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
62        f.root(&format!("i128: {}", self))
63    }
64}
65
66impl TreeDisplay for () {
67    fn tree_display(&self, f: &mut TreeFormatter, _source: &str) -> fmt::Result {
68        f.root("()")
69    }
70}