#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Span {
pub start: usize,
pub end: usize,
}
#[derive(Debug, Clone)]
pub struct FormatString {
pub segments: Vec<Segment>,
}
#[derive(Debug, Clone)]
pub enum Segment {
Literal(Span),
EscapedOpen,
EscapedClose,
Placeholder(Placeholder),
}
#[derive(Debug, Clone)]
pub struct Placeholder {
pub argument: Argument,
pub spec: FormatSpec,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Argument {
Implicit,
Positional(usize),
Named(Span),
}
#[derive(Debug, Clone)]
pub struct FormatSpec {
pub fill: Option<char>,
pub align: Option<Align>,
pub sign: Option<Sign>,
pub alternate: bool,
pub zero_pad: bool,
pub width: Option<Count>,
pub precision: Option<Precision>,
pub format_type: FormatType,
}
impl FormatSpec {
pub const fn default() -> Self {
Self {
fill: None,
align: None,
sign: None,
alternate: false,
zero_pad: false,
width: None,
precision: None,
format_type: FormatType::Display,
}
}
#[inline]
pub fn is_default(&self) -> bool {
self.fill.is_none()
&& self.align.is_none()
&& self.sign.is_none()
&& !self.alternate
&& !self.zero_pad
&& self.width.is_none()
&& self.precision.is_none()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Align {
Left,
Center,
Right,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Sign {
Plus,
Minus,
}
#[derive(Debug, Clone)]
pub enum Count {
Literal(usize),
Param(CountParam),
}
#[derive(Debug, Clone)]
pub enum CountParam {
Positional(usize),
Named(Span),
}
#[derive(Debug, Clone)]
pub enum Precision {
Count(Count),
Star,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormatType {
Display,
Debug,
DebugLowerHex,
DebugUpperHex,
Octal,
LowerHex,
UpperHex,
Binary,
LowerExp,
UpperExp,
Pointer,
}