#[derive(Clone, Copy, Debug, Default)]
pub struct Pos {
pub line: usize,
pub col: usize,
}
impl Pos {
pub fn from_span_start(span: proc_macro2::Span) -> Self {
let start = span.start();
Self {
line: start.line,
col: start.column,
}
}
pub fn from_span_end(span: proc_macro2::Span) -> Self {
let end = span.end();
Self {
line: end.line,
col: end.column,
}
}
}
pub fn spacing_between(prev_end: Pos, curr_start: Pos) -> String {
if curr_start.line > prev_end.line {
let newlines = curr_start.line - prev_end.line;
let indent = curr_start.col;
format!("{}{}", "\n".repeat(newlines), " ".repeat(indent))
} else if curr_start.col > prev_end.col {
" ".repeat(curr_start.col - prev_end.col)
} else {
String::new()
}
}