pub trait BlockParser<B: Send + 'static>:
Clone
+ Send
+ 'static {
// Required method
fn extract(&self, block: Block) -> Vec<B>;
// Provided methods
fn batch(&self, items: Vec<B>) -> Vec<B> { ... }
fn options() -> Options { ... }
fn parse(&self, headers: &[ParsedHeader]) -> Receiver<Result<B>> { ... }
fn parse_dir(&self, blocks: &str) -> Result<Receiver<Result<B>>> { ... }
fn parse_map<C: Send + 'static>(
&self,
headers: &[ParsedHeader],
map: fn(_: B) -> C,
) -> Receiver<Result<C>> { ... }
fn parse_with_opts(
&self,
headers: &[ParsedHeader],
opts: Options,
) -> Receiver<Result<B>> { ... }
fn parse_with_opts_map<C: Send + 'static>(
&self,
headers: &[ParsedHeader],
opts: Options,
map: fn(_: B) -> C,
) -> Receiver<Result<C>> { ... }
fn send_batch<C>(
&self,
tx_c: &Sender<Result<C>>,
batch: Result<Vec<B>>,
map: fn(_: B) -> C,
) { ... }
}
Expand description
Implement this trait to create a custom Block
parser.
Required Methods§
Provided Methods§
Sourcefn batch(&self, items: Vec<B>) -> Vec<B>
fn batch(&self, items: Vec<B>) -> Vec<B>
Runs on batches of B
to return the final results, blocks will be in-order if
Options::order_output
has been set.
Implement batch if your algorithm depends on the order of the blocks or if you need to
reduce lock contention when accessing shared state in Arc<Mutex<_>>
.
Use Options::batch_size
if you need to tune the number of the items
.
Sourcefn options() -> Options
fn options() -> Options
The default Options
that this parser will use.
Implementing BlockParser::options
allows for tuning of the parameters of the algorithm.
Sourcefn parse(&self, headers: &[ParsedHeader]) -> Receiver<Result<B>>
fn parse(&self, headers: &[ParsedHeader]) -> Receiver<Result<B>>
Parse all the blocks represented by the headers.
Sourcefn parse_dir(&self, blocks: &str) -> Result<Receiver<Result<B>>>
fn parse_dir(&self, blocks: &str) -> Result<Receiver<Result<B>>>
Parse all the blocks located in the blocks
directory
Sourcefn parse_map<C: Send + 'static>(
&self,
headers: &[ParsedHeader],
map: fn(_: B) -> C,
) -> Receiver<Result<C>>
fn parse_map<C: Send + 'static>( &self, headers: &[ParsedHeader], map: fn(_: B) -> C, ) -> Receiver<Result<C>>
Parse the blocks and then perform the map
function.
Use when performing expensive post-processing for a large speed-up.
The mapping will occur after BlockParser::batch
, keeping the ordering.
Sourcefn parse_with_opts(
&self,
headers: &[ParsedHeader],
opts: Options,
) -> Receiver<Result<B>>
fn parse_with_opts( &self, headers: &[ParsedHeader], opts: Options, ) -> Receiver<Result<B>>
Allows users to pass in custom Options
in case they need to reduce memory usage or
otherwise tune performance for their system. Users should call BlockParser::options
to get the default options associated with the parser first.
Sourcefn parse_with_opts_map<C: Send + 'static>(
&self,
headers: &[ParsedHeader],
opts: Options,
map: fn(_: B) -> C,
) -> Receiver<Result<C>>
fn parse_with_opts_map<C: Send + 'static>( &self, headers: &[ParsedHeader], opts: Options, map: fn(_: B) -> C, ) -> Receiver<Result<C>>
Pass in custom Options
and a map
function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.