Expand description
Handler which shortens matched data
it can be used e.g. shorten long strings
"some long text" -> "some lon..."
§Example
use streamson_lib::{handler, matcher, strategy::{self, Strategy}};
use std::sync::{Arc, Mutex};
let handler = Arc::new(Mutex::new(handler::Shorten::new(3, r#"..""#.to_string())));
let matcher = matcher::Simple::new(r#"{"elements"}[]{"description"}"#).unwrap();
let mut convert = strategy::Convert::new();
// Set the matcher for convert strategy
convert.add_matcher(Box::new(matcher), handler);
for input in vec![
br#"{"elements": [{"description": "too long string"}, {"#.to_vec(),
br#""description": "other long string"}]}"#.to_vec(),
] {
for converted_data in convert.process(&input).unwrap() {
println!("{:?}", converted_data);
}
}Structs§
- Shorten
- Handler which shortens the matched data