use crate::{ core::{Attributes, Operation, PlainTextAttributes}, rich_text::RichTextAttributes, }; pub type RichTextOpBuilder = OpBuilder; pub type PlainTextOpBuilder = OpBuilder; pub struct OpBuilder { ty: Operation, attrs: T, } impl OpBuilder where T: Attributes, { pub fn new(ty: Operation) -> OpBuilder { OpBuilder { ty, attrs: T::default(), } } pub fn retain(n: usize) -> OpBuilder { OpBuilder::new(Operation::Retain(n.into())) } pub fn delete(n: usize) -> OpBuilder { OpBuilder::new(Operation::Delete(n)) } pub fn insert(s: &str) -> OpBuilder { OpBuilder::new(Operation::Insert(s.into())) } pub fn attributes(mut self, attrs: T) -> OpBuilder { self.attrs = attrs; self } pub fn build(self) -> Operation { let mut operation = self.ty; match &mut operation { Operation::Delete(_) => {}, Operation::Retain(retain) => retain.attributes = self.attrs, Operation::Insert(insert) => insert.attributes = self.attrs, } operation } }