1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
//! Collections of handler (what to do with matched paths and data). use crate::{error, path::Path, streamer::Output}; pub mod buffer; pub mod file; pub mod indexer; pub mod println; pub use buffer::Buffer; pub use file::File; pub use indexer::Indexer; pub use println::PrintLn; /// Common handler trait pub trait Handler: Send { /// Calls handler on matched data /// /// # Arguments /// * `path` - path which was matched /// * `matcher_idx`- idx of matcher which was used /// * `data` - matched data /// /// # Returns /// * `Ok(())` - Handler was successfully executed /// * `Err(_)` - Failed to execute handler /// /// # Errors /// /// Handler failed (e.g. failed to write to output file). fn handle( &mut self, path: &Path, matcher_idx: usize, data: Option<&[u8]>, ) -> Result<(), error::Handler>; /// Calls when an index occured /// /// # Arguments /// * `path` - path which was matched /// * `idx` - input data index of next data after handle /// * `matcher_idx`- idx of matcher which was used fn handle_idx( &mut self, _path: &Path, _matcher_idx: usize, _idx: Output, ) -> Result<(), error::Handler> { Ok(()) } /// Should path be used fn use_path(&self) -> bool { false } /// A str which will be used to separate records fn separator(&self) -> &str { "\n" } /// If true is returned a buffer will /// be used to store input data when /// matcher matches /// /// Required for most of the handlers, /// but there can be situations where, /// it can be avioded fn buffering_required(&self) -> bool { true } }