phago_core/primitives/digest.rs
1//! DIGEST — Phagocytosis
2//!
3//! A macrophage engulfs foreign material, destroys it in a lysosome,
4//! and presents fragments on its surface via MHC proteins. Other immune
5//! cells read these fragments and mount targeted responses.
6//!
7//! **Key insight**: Destruction is the primary learning pathway. Every
8//! problem consumed becomes a lesson distributed to the network.
9//!
10//! In Rust, `engulf` takes ownership of the input — it is truly consumed,
11//! not copied. This is not a simulation of phagocytosis; Rust's move
12//! semantics ARE phagocytosis.
13
14use crate::types::DigestionResult;
15
16/// Consume input, break it down, and present extracted fragments.
17///
18/// The digestion cycle:
19/// 1. **Engulf** — take ownership of input (input ceases to exist)
20/// 2. **Lyse** — break engulfed material into structural fragments
21/// 3. **Present** — expose fragments for other agents to read
22pub trait Digest {
23 /// The raw input to consume. Ownership is transferred — the input is destroyed.
24 type Input;
25 /// Structural fragments extracted during digestion.
26 type Fragment;
27 /// What is presented to other agents after digestion.
28 type Presentation;
29
30 /// Engulf: take ownership of input.
31 ///
32 /// After this call, the input no longer exists independently.
33 /// The agent holds it internally for processing.
34 fn engulf(&mut self, input: Self::Input) -> DigestionResult;
35
36 /// Lyse: break the engulfed material into fragments.
37 ///
38 /// Analogous to lysosomal degradation. The internal material is
39 /// broken into structural pieces that can be analyzed and presented.
40 fn lyse(&mut self) -> Vec<Self::Fragment>;
41
42 /// Present: expose fragments on the agent's surface.
43 ///
44 /// Other agents can read this presentation (like T-cells reading
45 /// MHC-presented antigens). The presentation is a read-only view.
46 fn present(&self) -> Self::Presentation;
47
48 /// Run the full digestion cycle: engulf → lyse → present.
49 fn digest(&mut self, input: Self::Input) -> Self::Presentation {
50 self.engulf(input);
51 self.lyse();
52 self.present()
53 }
54}