pub trait OffloadPolicy<T: BlockMetadata>: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn evaluate<'a>(&'a self, ctx: &'a EvalContext<T>) -> PolicyFuture<'a>;
// Provided method
fn evaluate_batch<'a>(
&'a self,
contexts: &'a [EvalContext<T>],
) -> PolicyBatchFuture<'a> { ... }
}Expand description
Trait for offload policies that filter blocks.
Policies are evaluated as a chain - a block must pass ALL policies to proceed.
Each policy receives an EvalContext with block information and returns
Ok(true) to pass or Ok(false) to filter out.
§Performance
This trait uses Either<Ready, BoxFuture> instead of #[async_trait] to
avoid heap allocations for synchronous policies. Implement using:
sync_result(Ok(true))for synchronous policies (zero allocation)async_result(async { ... })for async policies (boxes the future)
§Batch Evaluation
The evaluate_batch method provides a default implementation that calls
evaluate for each block. Override for efficiency when the policy can
benefit from batching (e.g., batch registry lookups).
Required Methods§
Sourcefn evaluate<'a>(&'a self, ctx: &'a EvalContext<T>) -> PolicyFuture<'a>
fn evaluate<'a>(&'a self, ctx: &'a EvalContext<T>) -> PolicyFuture<'a>
Evaluate whether a block should be offloaded.
Returns:
Ok(true): Block passes this filter, continue to next policyOk(false): Block filtered out, remove from transferErr(_): Fatal error, fail the entire transfer
Provided Methods§
Sourcefn evaluate_batch<'a>(
&'a self,
contexts: &'a [EvalContext<T>],
) -> PolicyBatchFuture<'a>
fn evaluate_batch<'a>( &'a self, contexts: &'a [EvalContext<T>], ) -> PolicyBatchFuture<'a>
Batch evaluate multiple blocks.
Default implementation calls evaluate for each block.
Override for efficiency when batching is beneficial.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".