🦀 RUST PATTERN DIFFICULTY: Adept Structural

Decorator of the Arcane Ward

Attach additional responsibilities to an object dynamically.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RUST IDIOMATIC PATTERN //
pub trait CommLink {
    fn transmit(&self, data: &str) -> String;
}

pub struct BasicLink;
impl CommLink for BasicLink {
    fn transmit(&self, data: &str) -> String { data.to_string() }
}

pub struct EncryptedLink<T: CommLink> {
    inner: T,
}
impl<T: CommLink> EncryptedLink<T> {
    pub fn new(inner: T) -> Self { Self { inner } }
}
impl<T: CommLink> CommLink for EncryptedLink<T> {
    fn transmit(&self, data: &str) -> String {
        let encrypted = format!("~ENCRYPTED~{}~", data);
        self.inner.transmit(&encrypted)
    }
}

To layer defenses without fundamentally altering the core matrix is the essence of Abjuration. The Decorator pattern lets a cyber-mage dynamically bind additional wards and modifications—like encryption and compression algorithms—around a core communication link.

Instead of writing a sprawling inheritance tree of EncryptedCompressedLink, you simply wrap the base object in as many concentric rings of logic as the cyber-ritual demands.

Runic Tags: #structural #decorator #abjuration #wrapping