-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathformatteriteminfo.rs
48 lines (43 loc) · 1.31 KB
/
formatteriteminfo.rs
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
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (ToDO) formatteriteminfo
use std::fmt;
#[allow(clippy::enum_variant_names)]
#[derive(Copy, PartialEq, Eq)]
pub enum FormatWriter {
IntWriter(fn(u64) -> String),
FloatWriter(fn(f64) -> String),
MultibyteWriter(fn(&[u8]) -> String),
}
impl Clone for FormatWriter {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl fmt::Debug for FormatWriter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::IntWriter(ref p) => {
f.write_str("IntWriter:")?;
fmt::Pointer::fmt(p, f)
}
Self::FloatWriter(ref p) => {
f.write_str("FloatWriter:")?;
fmt::Pointer::fmt(p, f)
}
Self::MultibyteWriter(ref p) => {
f.write_str("MultibyteWriter:")?;
fmt::Pointer::fmt(&(*p as *const ()), f)
}
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct FormatterItemInfo {
pub byte_size: usize,
pub print_width: usize, // including a space in front of the text
pub formatter: FormatWriter,
}