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§
Sourcefn base(&self) -> &CardTraitBase
fn base(&self) -> &CardTraitBase
Borrow the underlying CardTraitBase. Implementors own a
CardTraitBase (directly or transitively) and return a reference.
Provided Methods§
Sourcefn resolve_source_player(&self, src_card: &Card) -> PlayerId
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.
Sourcefn matches_valid(
&self,
target: &MatchValidTarget<'_>,
valids: &[&str],
src_card: Option<&Card>,
) -> bool
fn matches_valid( &self, target: &MatchValidTarget<'_>, valids: &[&str], src_card: Option<&Card>, ) -> bool
Mirrors matchesValid(Object, String[], Card).
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
Sourcefn matches_valid_card(&self, expr: &str, card: &Card, source: &Card) -> bool
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").
fn matches_compiled_valid_card( &self, selector: &CompiledSelector, card: &Card, source: &Card, ) -> bool
Sourcefn matches_valid_player(
&self,
expr: &str,
player: PlayerId,
source: &Card,
) -> bool
fn matches_valid_player( &self, expr: &str, player: PlayerId, source: &Card, ) -> bool
Ergonomic comma-separated-expression wrapper over matches_valid for
player targets.
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§
impl CardTrait for CardTraitBase
impl CardTrait for ReplacementEffect
impl CardTrait for StaticAbility
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.