use std::fmt;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct LineComment {
text: String,
}
impl LineComment {
pub fn try_new(s: &str) -> Result<LineComment, String> {
if s.contains('\n') {
return Err("Line comment cannot contain a newline.".into());
}
Ok(LineComment { text: s.to_owned() })
}
pub fn invert(&self) -> LineComment {
self.clone()
}
pub fn text(&self) -> &str {
&self.text
}
}
impl fmt::Display for LineComment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "//{}", self.text)
}
}