use std::fmt::{self, Write};
use crate::formatter::Formatter;
#[derive(Debug, Clone)]
pub struct Include {
path: String,
is_system: bool,
doc: Option<String>,
}
impl Include {
pub fn new(path: &str) -> Self {
Self::with_string(String::from(path))
}
pub fn with_string(path: String) -> Self {
Include {
path,
is_system: false,
doc: None,
}
}
pub fn new_system(path: &str) -> Self {
Include {
path: String::from(path),
is_system: true,
doc: None,
}
}
pub fn doc_str(&mut self, doc: &str) -> &mut Self {
self.doc = Some(String::from(doc));
self
}
pub fn system(&mut self, arg: bool) -> &mut Self {
self.is_system = arg;
self
}
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
write!(fmt, "#include ")?;
if self.is_system {
write!(fmt, "<{}>", self.path)?;
} else {
write!(fmt, "\"{}\"", self.path)?;
}
if let Some(d) = &self.doc {
writeln!(fmt, " // {d}")
} else {
writeln!(fmt)
}
}
}