use decor::InternalString;
use parser;
use std::str::FromStr;
use table::{Item, Iter, Table};
#[derive(Debug, Clone)]
pub struct Document {
pub root: Item,
pub(crate) trailing: InternalString,
}
impl Default for Document {
fn default() -> Self {
Self {
root: Item::Table(Table::default()),
trailing: Default::default(),
}
}
}
impl Document {
pub fn new() -> Self {
Default::default()
}
pub fn as_table(&self) -> &Table {
self.root.as_table().expect("root should always be a table")
}
pub fn as_table_mut(&mut self) -> &mut Table {
self.root
.as_table_mut()
.expect("root should always be a table")
}
pub fn iter(&self) -> Iter {
self.root
.as_table()
.expect("root should always be a table")
.iter()
}
}
impl FromStr for Document {
type Err = parser::TomlError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
parser::TomlParser::parse(s)
}
}