indent_display/
defaults.rs

1/*a Copyright
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7  http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14
15@file    indent.rs
16@brief   An indented display system
17 */
18
19//a Imports
20use crate::{DefaultIndentedDisplay, IndentedDisplay, IndentedOptions, Indenter, NullOptions};
21
22//a DefaultIndentedDisplay implementation
23//ti IndentedDisplay for DefaultIndentedDisplay
24impl<'a, O: IndentedOptions<'a>, T: DefaultIndentedDisplay> IndentedDisplay<'a, O> for T {
25    fn indent(&self, ind: &mut Indenter<'a, O>) -> std::fmt::Result {
26        use std::fmt::Write;
27        write!(ind, "{}", self)
28    }
29}
30
31//ti DefaultIndentedDisplay for base types
32impl DefaultIndentedDisplay for u8 {}
33impl DefaultIndentedDisplay for u16 {}
34impl DefaultIndentedDisplay for u32 {}
35impl DefaultIndentedDisplay for u64 {}
36impl DefaultIndentedDisplay for u128 {}
37impl DefaultIndentedDisplay for usize {}
38impl DefaultIndentedDisplay for i8 {}
39impl DefaultIndentedDisplay for i16 {}
40impl DefaultIndentedDisplay for i32 {}
41impl DefaultIndentedDisplay for i64 {}
42impl DefaultIndentedDisplay for i128 {}
43impl DefaultIndentedDisplay for isize {}
44impl DefaultIndentedDisplay for &str {}
45impl DefaultIndentedDisplay for String {}
46impl<'a, Opt: IndentedOptions<'a>, T: IndentedDisplay<'a, Opt>> IndentedDisplay<'a, Opt> for [T] {
47    //mp fmt
48    /// Display for humans with indent
49    fn indent(&self, f: &mut Indenter<'a, Opt>) -> std::fmt::Result {
50        use std::fmt::Write;
51        write!(f, "[\n")?;
52        {
53            let mut sub = f.sub();
54            for x in self.iter() {
55                x.indent(&mut sub)?;
56                write!(sub, ",\n")?;
57            }
58        }
59        write!(f, "]\n")
60    }
61}
62
63//a NullOptions
64//ti IndentedOptions
65impl IndentedOptions<'_> for NullOptions {}