pub trait BeginXp{
// Provided method
fn begin_xp(
owner: &Self::Owner,
key: &Self::XpKey,
points: Self::Points,
) -> DispatchResult { ... }
}Expand description
Blanket Trait for safe initialization and earning of XP entries.
BeginXp by default extends XpReap to provide a unified entry point
for initializing new XP records or earning XP on existing ones, while ensuring
that reaped (finalized) XP keys cannot be reused.
This trait encapsulates guarded creation logic, preventing accidental re-initialization of finalized XP entries and enforcing correct lifecycle transitions.
Provided Methods§
Sourcefn begin_xp(
owner: &Self::Owner,
key: &Self::XpKey,
points: Self::Points,
) -> DispatchResult
fn begin_xp( owner: &Self::Owner, key: &Self::XpKey, points: Self::Points, ) -> DispatchResult
Initializes a new XP entry or earns XP based on the current state of the key.
This method provides state-aware XP management with the following behavior:
- If the XP key does not exist and has never been reaped, creates a new XP entry for the owner
- If the XP key exists and is not reaped, earns (increments) XP by the specified points
- If the XP key has been reaped (finalized), prevents any operation and returns an error
This unified approach ensures that XP operations respect the complete lifecycle, preventing resurrection of finalized entries while enabling seamless creation and growth of valid ones. The method serves as a safe entry point that handles all edge cases.
§Returns
Ok(())if the XP entry is successfully created or XP is successfully earned.Err(DispatchError)if the XP key has been reaped or any underlying operation fails.
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.