Skip to main content

normalizer_tr/
normalizer.rs

1use std::sync::Arc;
2
3use crate::{
4    NORMALIZER_ID, NormalizeError, NormalizeOptions, NormalizeResult, WorkControl, pipeline,
5    resources::Resources,
6};
7
8/// Immutable, thread-safe normalizer. Clones share validated built-in resources.
9#[derive(Clone)]
10pub struct Normalizer {
11    resources: Arc<Resources>,
12}
13
14impl Normalizer {
15    /// Diagnostic identity of the one built-in normalizer.
16    pub fn normalizer_id(&self) -> &'static str {
17        NORMALIZER_ID
18    }
19    /// Create the built-in normalizer, validating its immutable resources.
20    pub fn new() -> Result<Self, NormalizeError> {
21        Ok(Self {
22            resources: Resources::shared()?,
23        })
24    }
25    /// Normalize synchronously with default, uncancelled work control.
26    pub fn normalize(
27        &self,
28        input: &str,
29        options: &NormalizeOptions,
30    ) -> Result<NormalizeResult, NormalizeError> {
31        self.normalize_controlled(input, options, &WorkControl::default())
32    }
33    /// Normalize with cooperative cancellation and an optional deadline.
34    pub fn normalize_controlled(
35        &self,
36        input: &str,
37        options: &NormalizeOptions,
38        control: &WorkControl,
39    ) -> Result<NormalizeResult, NormalizeError> {
40        pipeline::run(input, options, control, &self.resources)
41    }
42}