use crate::context::block::ContextBlock;
use serde::Serialize;
use super::EditFailure;
#[derive(Debug, Clone)]
pub struct ContextFrame {
pub blocks: Vec<ContextBlock>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct Context {
pub(super) blocks: Vec<ContextBlock>,
}
impl Context {
pub fn new() -> Self {
Self::default()
}
pub fn from_blocks(blocks: Vec<ContextBlock>) -> Result<Self, EditFailure> {
let mut context = Self::new();
context.apply(Vec::new(), blocks)?;
Ok(context)
}
pub fn blocks(&self) -> &[ContextBlock] {
&self.blocks
}
pub fn into_blocks(self) -> Vec<ContextBlock> {
self.blocks
}
pub fn frame(&self) -> ContextFrame {
ContextFrame {
blocks: self.blocks.clone(),
}
}
}