use std::ops::Deref;
use std::slice::Iter;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Equation {
text: String,
label: Option<String>,
not_numbered: bool,
}
impl Equation {
pub fn new<S: AsRef<str>>(src: S) -> Equation {
Equation {
text: src.as_ref().to_string(),
label: None,
not_numbered: false,
}
}
pub fn with_label(label: &str, text: &str) -> Equation {
let mut eq = Equation::new(text);
eq.label(label);
eq
}
pub fn label(&mut self, name: &str) -> &mut Self {
self.label = Some(name.to_string());
self
}
pub fn text(&mut self, src: &str) -> &mut Self {
self.text = src.to_string();
self
}
pub fn not_numbered(&mut self) -> &mut Self {
self.not_numbered = true;
self
}
pub fn get_text(&self) -> &str {
&self.text
}
pub fn get_label(&self) -> Option<&str> {
self.label.as_ref().map(Deref::deref)
}
pub fn is_numbered(&self) -> bool {
!self.not_numbered
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Align {
items: Vec<Equation>,
}
impl Align {
pub fn new() -> Align {
Default::default()
}
pub fn iter(&self) -> Iter<Equation> {
self.items.iter()
}
pub fn push<E: Into<Equation>>(&mut self, eq: E) -> &mut Self {
self.items.push(eq.into());
self
}
}
impl<'a> From<&'a str> for Equation {
fn from(other: &'a str) -> Equation {
Equation::new(other)
}
}
impl<'a> From<&'a str> for Align {
fn from(other: &'a str) -> Align {
let mut eq = Align::new();
eq.push(other);
eq
}
}