pub trait PenalizeAuthors<Author, Penalty>where
Author: Keyed,
Penalty: Percentage,{
type PenaltyFor: Buffer<(Author, Penalty)>;
type PenaltyModel: PurePluginModel<Self::PenaltyFor, <Self::PenaltyContext as ModelContext>::Context, Self::PenaltyFor> + Default;
type PenaltyContext: ModelContext;
// Required method
fn penalize(who: &Author, penalty: Penalty) -> DispatchResult;
// Provided methods
fn penalize_authors(towards: Self::PenaltyFor) { ... }
fn transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor { ... }
fn on_penalty_success(_who: &Author, _penalty: Penalty) { ... }
fn on_penalty_fail(_who: &Author, _err: DispatchError) { ... }
}Expand description
Provides a plugin-driven penalty system for authors, allowing permanent penalties to be applied in a modular and runtime-configurable way.
§Core Responsibilities
- Accept a set of authors and penalties (
Self::PenaltyFor). - Transform penalties via a runtime-configurable
Self::PenaltyModelplugin. - Apply penalties individually with safe callbacks for success or failure.
§Type Parameters
Author: Entity receiving the penalty.Penalty: Type representing the penalty (e.g., token deduction, score reduction).
Required Associated Types§
Sourcetype PenaltyFor: Buffer<(Author, Penalty)>
type PenaltyFor: Buffer<(Author, Penalty)>
Collection of authors and their associated penalties for normalization.
- Represents the input to the
Self::PenaltyModelplugin. - Represents the output after plugin transformation.
- Supports iteration, extension, and default construction.
Sourcetype PenaltyModel: PurePluginModel<Self::PenaltyFor, <Self::PenaltyContext as ModelContext>::Context, Self::PenaltyFor> + Default
type PenaltyModel: PurePluginModel<Self::PenaltyFor, <Self::PenaltyContext as ModelContext>::Context, Self::PenaltyFor> + Default
The plugin model implementing the penalty transformation logic.
- Input:
Self::PenaltyForcollection. - Output: Transformed
Self::PenaltyForcollection.
Transforms the mapping from (Author, Penalty) to (Author, Penalty).
Sourcetype PenaltyContext: ModelContext
type PenaltyContext: ModelContext
Provides optional runtime parameters for the penalty-transformation
plugin Self::PenaltyModel computation.
Enables dynamic configuration, such as thresholds, multipliers, or other runtime-adjustable settings.
Required Methods§
Sourcefn penalize(who: &Author, penalty: Penalty) -> DispatchResult
fn penalize(who: &Author, penalty: Penalty) -> DispatchResult
Applies a single penalty to an author.
This is a direct application of a penalty and does not involve
transformation via the Self::PenaltyModel plugin.
Provided Methods§
Apply penalties to a list of authors.
Workflow:
- Transform input penalties using
Self::PenaltyModel. - Apply penalties to each author via
Self::penalize. - Call
Self::on_penalty_successorSelf::on_penalty_failfor each author.
Notes:
- Handles multiple penalties or single penalty uniformly.
- Failures for individual authors do not halt the process.
Sourcefn transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor
fn transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor
Transforms raw penalties using the Self::PenaltyModel plugin.
- Applies runtime-configured rules, multipliers, or caps.
- Utilizes the plugin model’s context
Self::PenaltyContext
Sourcefn on_penalty_success(_who: &Author, _penalty: Penalty)
fn on_penalty_success(_who: &Author, _penalty: Penalty)
Callback invoked after a successful individual penalty.
Can be used for logging, metrics, or side-effects.
Default is no-op
Sourcefn on_penalty_fail(_who: &Author, _err: DispatchError)
fn on_penalty_fail(_who: &Author, _err: DispatchError)
Callback invoked when an author penalty fails.
Can be used for logging, alerting, or retry logic.
Default is no-op
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.