use crate::model::{InsertError, ReplaceError, ResolveErr, Schema, SliceError};
use derivative::Derivative;
use displaydoc::Display;
use thiserror::Error;
use super::map::{Mappable, StepMap};
#[derive(Derivative, Display, Error)]
#[derivative(Debug(bound = ""))]
pub enum StepError<S: Schema> {
WouldOverwrite,
GapWouldOverwrite,
GapNotFlat,
GapNotFit,
Resolve(#[from] ResolveErr),
Replace(#[from] ReplaceError<S>),
Slice(#[from] SliceError),
Insert(#[from] InsertError),
NoNodeAtPosition,
InvalidAttr(String),
}
#[allow(type_alias_bounds)]
pub type StepResult<S: Schema> = Result<S::Node, StepError<S>>;
pub trait StepKind<S: Schema> {
fn apply(&self, doc: &S::Node) -> StepResult<S>;
fn get_map(&self) -> StepMap {
StepMap::EMPTY
}
fn invert(&self, doc: &S::Node) -> super::Step<S>;
fn map<M: Mappable>(&self, mapping: &M) -> Option<super::Step<S>>;
fn merge(&self, _other: &super::Step<S>) -> Option<super::Step<S>> {
None
}
}