Skip to main content

CardTrait

Trait CardTrait 

Source
pub trait CardTrait {
    // Required method
    fn base(&self) -> &CardTraitBase;

    // Provided methods
    fn resolve_source_player(&self, src_card: &Card) -> PlayerId { ... }
    fn matches_valid(
        &self,
        target: &MatchValidTarget<'_>,
        valids: &[&str],
        src_card: Option<&Card>,
    ) -> bool { ... }
    fn matches_compiled_valid(
        &self,
        target: &MatchValidTarget<'_>,
        selector: &CompiledSelector,
        src_card: Option<&Card>,
    ) -> bool { ... }
    fn matches_valid_param(
        &self,
        param: &str,
        target: &MatchValidTarget<'_>,
        src_card: Option<&Card>,
    ) -> bool { ... }
    fn matches_valid_card(&self, expr: &str, card: &Card, source: &Card) -> bool { ... }
    fn matches_compiled_valid_card(
        &self,
        selector: &CompiledSelector,
        card: &Card,
        source: &Card,
    ) -> bool { ... }
    fn matches_valid_player(
        &self,
        expr: &str,
        player: PlayerId,
        source: &Card,
    ) -> bool { ... }
    fn matches_compiled_valid_player(
        &self,
        selector: &CompiledSelector,
        player: PlayerId,
        source: &Card,
    ) -> bool { ... }
}
Expand description

Polymorphic facade over CardTraitBase — the Rust stand-in for Java’s inheritance chain where Trigger, ReplacementEffect, and StaticAbility extend CardTraitBase. Because Rust structs have no virtual methods, the this instanceof Trigger self-type dispatch in Java’s matchesValid is expressed here as the resolve_source_player hook: the default returns src_card.controller, and Trigger overrides it to consult its spawning ability’s activating player.

Required Methods§

Source

fn base(&self) -> &CardTraitBase

Borrow the underlying CardTraitBase. Implementors own a CardTraitBase (directly or transitively) and return a reference.

Provided Methods§

Source

fn resolve_source_player(&self, src_card: &Card) -> PlayerId

Resolves the player whose perspective is used for Valid$ expressions. Default matches Java’s base behavior (source card’s controller). Trigger overrides — mirrors this instanceof Trigger in Java CardTraitBase.matchesValid(Object, String[], Card) at line 214.

Source

fn matches_valid( &self, target: &MatchValidTarget<'_>, valids: &[&str], src_card: Option<&Card>, ) -> bool

Mirrors matchesValid(Object, String[], Card).

Source

fn matches_compiled_valid( &self, target: &MatchValidTarget<'_>, selector: &CompiledSelector, src_card: Option<&Card>, ) -> bool

Source

fn matches_valid_param( &self, param: &str, target: &MatchValidTarget<'_>, src_card: Option<&Card>, ) -> bool

Source

fn matches_valid_card(&self, expr: &str, card: &Card, source: &Card) -> bool

Ergonomic comma-separated-expression wrapper over matches_valid for card targets. Mirrors Java’s matchesValid(Object, String[], Card) call pattern where valids is often a single comma-separated string (e.g. "Creature.YouCtrl,Artifact").

Source

fn matches_compiled_valid_card( &self, selector: &CompiledSelector, card: &Card, source: &Card, ) -> bool

Source

fn matches_valid_player( &self, expr: &str, player: PlayerId, source: &Card, ) -> bool

Ergonomic comma-separated-expression wrapper over matches_valid for player targets.

Source

fn matches_compiled_valid_player( &self, selector: &CompiledSelector, player: PlayerId, source: &Card, ) -> bool

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl CardTrait for CardTraitBase

Source§

impl CardTrait for ReplacementEffect

Source§

impl CardTrait for StaticAbility

Source§

impl CardTrait for Trigger

Mirrors Java’s Trigger extends CardTraitBase override of matchesValid: when this instanceof Trigger and a spawning ability is present, the source player resolves to the spawning ability’s activating player rather than the source card’s controller.