use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TargetError {
NotFound,
OutOfBounds,
InvalidPosition {
line: usize,
col: Option<usize>,
},
#[cfg(feature = "regex")]
InvalidPattern(String),
}
impl fmt::Display for TargetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotFound => write!(f, "Target not found in rope"),
Self::OutOfBounds => write!(f, "Target index out of bounds"),
Self::InvalidPosition {
line,
col: Some(col),
} => {
write!(f, "Invalid position: line {line}, column {col}")
}
Self::InvalidPosition { line, col: None } => {
write!(f, "Invalid position: line {line}")
}
#[cfg(feature = "regex")]
Self::InvalidPattern(msg) => write!(f, "Invalid regex pattern: {msg}"),
}
}
}
impl std::error::Error for TargetError {}