Skip to main content

manabrew_engine/keyword/
trait_keywords_change.rs

1//! Interface for keyword changes.
2//!
3//! Ported from Java's `IKeywordsChange.java` in `forge/game/keyword/`.
4
5use super::keyword_collection::KeywordCollection;
6
7/// Trait for objects that can apply keyword changes to a collection.
8/// Mirrors Java's `IKeywordsChange` interface.
9pub trait KeywordsChange: KeywordsChangeClone {
10    /// Apply this change to a keyword collection.
11    fn apply_keywords(&self, list: &mut KeywordCollection);
12
13    /// Create a deep copy of this keywords change.
14    /// Mirrors Java's `IKeywordsChange.copy(Card, boolean)`.
15    fn copy(&self) -> Box<dyn KeywordsChange>;
16}
17
18/// Helper trait for cloning boxed `KeywordsChange` trait objects.
19pub trait KeywordsChangeClone {
20    fn clone_box(&self) -> Box<dyn KeywordsChange>;
21}
22
23impl<T: 'static + KeywordsChange + Clone> KeywordsChangeClone for T {
24    fn clone_box(&self) -> Box<dyn KeywordsChange> {
25        Box::new(self.clone())
26    }
27}
28
29impl Clone for Box<dyn KeywordsChange> {
30    fn clone(&self) -> Self {
31        self.clone_box()
32    }
33}