Trait PenalizeAuthors

Source
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

  1. Accept a set of authors and penalties (Self::PenaltyFor).
  2. Transform penalties via a runtime-configurable Self::PenaltyModel plugin.
  3. 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§

Source

type PenaltyFor: Buffer<(Author, Penalty)>

Collection of authors and their associated penalties for normalization.

  • Represents the input to the Self::PenaltyModel plugin.
  • Represents the output after plugin transformation.
  • Supports iteration, extension, and default construction.
Source

type PenaltyModel: PurePluginModel<Self::PenaltyFor, <Self::PenaltyContext as ModelContext>::Context, Self::PenaltyFor> + Default

The plugin model implementing the penalty transformation logic.

Transforms the mapping from (Author, Penalty) to (Author, Penalty).

Source

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§

Source

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§

Source

fn penalize_authors(towards: Self::PenaltyFor)

Apply penalties to a list of authors.

Workflow:

  1. Transform input penalties using Self::PenaltyModel.
  2. Apply penalties to each author via Self::penalize.
  3. Call Self::on_penalty_success or Self::on_penalty_fail for each author.

Notes:

  • Handles multiple penalties or single penalty uniformly.
  • Failures for individual authors do not halt the process.
Source

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
Source

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

Source

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.

Implementors§