mod deletion;
#[cfg(feature = "german")]
mod german;
mod lower;
mod normalization;
pub mod replace;
mod style;
#[cfg(feature = "symbols")]
mod symbols;
mod titlecase;
mod upper;
use std::error::Error;
use std::fmt;
pub use deletion::Deletion;
#[cfg(feature = "german")]
pub use german::German;
pub use lower::Lower;
pub use normalization::Normalization;
pub use replace::{Replacement, ReplacementError};
pub use style::Style;
#[cfg(feature = "symbols")]
pub use symbols::{Symbols, inversion::Symbols as SymbolsInversion};
pub use titlecase::Titlecase;
pub use upper::Upper;
use crate::scoping::scope::ScopeContext;
pub trait Action: Send + Sync {
fn act(&self, input: &str) -> String;
fn act_with_context(
&self,
input: &str,
context: &ScopeContext<'_>,
) -> Result<String, ActionError> {
let _ = context; Ok(self.act(input))
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ActionError {
ReplacementError(ReplacementError),
}
impl fmt::Display for ActionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ReplacementError(re) => {
write!(f, "Action failed in replacement: {re}")
}
}
}
}
impl Error for ActionError {}
impl<T> Action for T
where
T: Fn(&str) -> String + Send + Sync,
{
fn act(&self, input: &str) -> String {
self(input)
}
}
impl Action for Box<dyn Action> {
fn act(&self, input: &str) -> String {
self.as_ref().act(input)
}
fn act_with_context(
&self,
input: &str,
context: &ScopeContext<'_>,
) -> Result<String, ActionError> {
self.as_ref().act_with_context(input, context)
}
}