This commit is contained in:
38
docs/snippets/rust/plugins/min_length_validator.md
Normal file
38
docs/snippets/rust/plugins/min_length_validator.md
Normal file
@@ -0,0 +1,38 @@
|
||||
```rust title="Rust"
|
||||
use kreuzberg::plugins::{Plugin, Validator};
|
||||
use kreuzberg::{Result, ExtractionResult, ExtractionConfig, KreuzbergError};
|
||||
use async_trait::async_trait;
|
||||
|
||||
struct MinLengthValidator {
|
||||
min_length: usize,
|
||||
}
|
||||
|
||||
impl Plugin for MinLengthValidator {
|
||||
fn name(&self) -> &str { "min-length-validator" }
|
||||
fn version(&self) -> String { "1.0.0".to_string() }
|
||||
fn initialize(&self) -> Result<()> { Ok(()) }
|
||||
fn shutdown(&self) -> Result<()> { Ok(()) }
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Validator for MinLengthValidator {
|
||||
async fn validate(
|
||||
&self,
|
||||
result: &ExtractionResult,
|
||||
_config: &ExtractionConfig,
|
||||
) -> Result<()> {
|
||||
if result.content.len() < self.min_length {
|
||||
return Err(KreuzbergError::validation(format!(
|
||||
"Content too short: {} < {} characters",
|
||||
result.content.len(),
|
||||
self.min_length
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn priority(&self) -> i32 {
|
||||
100
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user