Skip to main content

MovementMemory

Struct MovementMemory 

Source
pub struct MovementMemory {
    pub transitions: Vec<Transition>,
}

Fields§

§transitions: Vec<Transition>

Implementations§

Source§

impl MovementMemory

Source

pub fn current_hash(&self) -> HashValue

Source

pub fn verify_integrity(&self) -> bool

Source

pub fn compose(&self, start: usize, end: usize) -> Option<MovementComposition>

Examples found in repository?
examples/demo.rs (line 131)
14fn main() {
15    let mut reality = Reality::new(
16        Identity("demo-reality".to_string()),
17        Boundary {
18            allowed_values: vec![
19                "before".to_string(),
20                "after".to_string(),
21                "done".to_string(),
22            ],
23        },
24        Law {
25            allowed_transitions: vec![
26                ("before".to_string(), "after".to_string()),
27                ("after".to_string(), "done".to_string()),
28            ],
29        },
30        State {
31            field: "before".to_string(),
32        },
33    );
34
35    let original = reality.clone();
36
37    let events = vec![
38        Event {
39            proposed_field: "after".to_string(),
40        },
41        Event {
42            proposed_field: "done".to_string(),
43        },
44    ];
45
46    println!("Preflight Checks:");
47    for (i, event) in events.iter().enumerate() {
48        println!(
49            "  event {} ({:?}) would_accept = {}",
50            i + 1,
51            event.proposed_field,
52            reality.would_accept(event)
53        );
54    }
55
56    let preflight = reality.preflight_sequence(&events);
57    println!("\nPreflight Sequence Report:");
58    println!("  results = {:?}", preflight.results);
59    println!("  sequence lawful = {}", preflight.sequence_lawful);
60    println!("  transition count = {}", preflight.transition_count);
61    match &preflight.final_state {
62        Some(state) => println!("  final state = {:?}", state),
63        None => println!("  final state = None"),
64    }
65
66    match plan_sequence(&reality, events.clone()) {
67        Ok(planned) => {
68            println!("\nPlanned Sequence:");
69            println!("  final state = {:?}", planned.final_state);
70            println!("  transitions planned = {}", planned.transition_count);
71        }
72        Err(e) => eprintln!("Planned sequence failed: {:?}", e),
73    }
74
75    match simulate_sequence(&reality, events.clone()) {
76        Ok(simulation) => {
77            println!("\nSimulation Report:");
78            println!(
79                "  planned final state = {:?}",
80                simulation.planned.final_state
81            );
82            println!(
83                "  planned transition count = {}",
84                simulation.planned.transition_count
85            );
86            println!("  simulated fingerprint = {:?}", simulation.fingerprint);
87            println!(
88                "  simulated memory integrity = {}",
89                simulation.integrity.memory_integrity
90            );
91            println!(
92                "  simulated drift required = {}",
93                simulation.integrity.drift.hidden_drift_required
94            );
95            println!(
96                "  simulated composition present = {}",
97                simulation.composition.is_some()
98            );
99        }
100        Err(e) => eprintln!("Simulation failed: {:?}", e),
101    }
102
103    match perform_movement_sequence(&mut reality, events) {
104        Ok(proofs) => {
105            println!("\nMovement sequence succeeded.");
106            for (i, proof) in proofs.iter().enumerate() {
107                println!("Step {}: proof_status = {}", i + 1, proof.proof_status);
108                println!("  law_check_result = {}", proof.law_check_result);
109                println!("  continuity_result = {}", proof.continuity_result);
110                println!("  hidden_drift_required = {}", proof.hidden_drift_required);
111            }
112
113            let report = reality.verify();
114            println!("\nVerification Report:");
115            println!("  replay passed = {}", report.replay.passed);
116            println!("  continuity preserved = {}", report.continuity.preserved);
117            println!("  memory integrity = {}", report.memory_integrity);
118            println!("  final state = {:?}", report.inspection.current_state);
119
120            let drift = reality.drift_check();
121            println!("\nDrift Check:");
122            println!("  hidden drift required = {}", drift.hidden_drift_required);
123            println!(
124                "  hidden boundary growth = {}",
125                drift.hidden_boundary_growth_detected
126            );
127            println!("  hidden law growth = {}", drift.hidden_law_growth_detected);
128
129            let comp = reality
130                .memory()
131                .compose(0, 1)
132                .expect("composition should exist");
133            println!("\nMovement Composition:");
134            println!("  start state: {:?}", comp.start_state);
135            println!("  end state: {:?}", comp.end_state);
136            println!("  verified: {}", comp.verify(reality.memory()));
137
138            let fingerprint = reality.fingerprint();
139            println!("\nReality Fingerprint:");
140            println!("  fingerprint = {:?}", fingerprint);
141
142            let integrity = reality.integrity_report();
143            println!("\nUnified Integrity Report:");
144            println!("  fingerprint = {:?}", integrity.fingerprint);
145            println!("  memory integrity = {}", integrity.memory_integrity);
146            println!(
147                "  drift required = {}",
148                integrity.drift.hidden_drift_required
149            );
150            println!("  replay passed = {}", integrity.replay.passed);
151            println!(
152                "  continuity preserved = {}",
153                integrity.continuity.preserved
154            );
155            println!("  state = {:?}", integrity.state);
156            println!("  transition count = {}", integrity.transition_count);
157
158            let diff = reality.diff(&original);
159            println!("\nReality Diff (original -> current):");
160            println!("  identity same = {}", diff.identity_same);
161            println!("  boundary same = {}", diff.boundary_same);
162            println!("  law same = {}", diff.law_same);
163            println!("  state same = {}", diff.state_same);
164            println!("  initial state same = {}", diff.initial_state_same);
165            println!("  birth boundary same = {}", diff.birth_boundary_same);
166            println!("  birth law same = {}", diff.birth_law_same);
167            println!("  memory hash same = {}", diff.memory_hash_same);
168            println!("  transition count same = {}", diff.transition_count_same);
169            println!("  fingerprint same = {}", diff.fingerprint_same);
170
171            let snapshot = reality.snapshot();
172            println!("\nReality Snapshot:");
173            println!("  identity = {:?}", snapshot.identity);
174            println!("  state = {:?}", snapshot.state);
175            println!("  transition count = {}", snapshot.transition_count);
176            println!("  memory hash = {:?}", snapshot.memory_hash);
177            println!("  fingerprint = {:?}", snapshot.fingerprint);
178
179            let snapshot_matches = snapshot.matches_current(&reality);
180            println!("\nSnapshot Comparison:");
181            println!("  matches current = {}", snapshot_matches);
182
183            let snapshot_diff = snapshot.diff_against(&reality);
184            println!("  snapshot diff vs current:");
185            println!("    identity same = {}", snapshot_diff.identity_same);
186            println!("    boundary same = {}", snapshot_diff.boundary_same);
187            println!("    law same = {}", snapshot_diff.law_same);
188            println!("    state same = {}", snapshot_diff.state_same);
189            println!(
190                "    initial state same = {}",
191                snapshot_diff.initial_state_same
192            );
193            println!("    memory hash same = {}", snapshot_diff.memory_hash_same);
194            println!(
195                "    transition count same = {}",
196                snapshot_diff.transition_count_same
197            );
198            println!("    fingerprint same = {}", snapshot_diff.fingerprint_same);
199
200            // Persistence demonstration
201            let tmp = env::temp_dir();
202            let reality_path = tmp.join("archimedes-demo-reality.bin");
203            let snapshot_path = tmp.join("archimedes-demo-snapshot.bin");
204
205            save_reality(&reality, &reality_path).unwrap();
206            save_snapshot(&snapshot, &snapshot_path).unwrap();
207
208            let loaded_reality = load_reality(&reality_path).unwrap();
209            let loaded_snapshot = load_snapshot(&snapshot_path).unwrap();
210
211            println!("\nUnsigned Persistence:");
212            println!(
213                "  loaded reality integrity = {}",
214                loaded_reality.memory_integrity()
215            );
216            println!(
217                "  loaded reality matches current = {}",
218                loaded_reality.diff(&reality).fingerprint_same
219            );
220            println!(
221                "  loaded snapshot matches saved = {}",
222                loaded_snapshot.matches_current(&reality)
223            );
224
225            // Signed persistence demonstration
226            let mut csprng = OsRng;
227            let signing_key = SigningKey::generate(&mut csprng);
228            let public_key = signing_key.verifying_key().to_bytes();
229
230            let signed_reality = sign_reality(&reality, &signing_key).unwrap();
231            let signed_path = tmp.join("archimedes-demo-signed-reality.bin");
232            save_signed_reality(&signed_reality, &signed_path).unwrap();
233
234            let loaded_signed: SignedReality =
235                load_signed_reality(&signed_path, &public_key).unwrap();
236            println!("\nSigned Persistence:");
237            println!(
238                "  signed reality integrity = {}",
239                loaded_signed.reality.memory_integrity()
240            );
241            println!(
242                "  signed reality matches current = {}",
243                loaded_signed.reality.diff(&reality).fingerprint_same
244            );
245            println!("  signature valid = true");
246
247            let _ = std::fs::remove_file(&reality_path);
248            let _ = std::fs::remove_file(&snapshot_path);
249            let _ = std::fs::remove_file(&signed_path);
250
251            println!("\nFinal state: {:?}", reality.state());
252            println!(
253                "Transitions recorded: {}",
254                reality.memory().transitions.len()
255            );
256        }
257        Err(e) => {
258            eprintln!("Movement sequence failed: {:?}", e);
259        }
260    }
261}

Trait Implementations§

Source§

impl Clone for MovementMemory

Source§

fn clone(&self) -> MovementMemory

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MovementMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MovementMemory

Source§

fn default() -> MovementMemory

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MovementMemory

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for MovementMemory

Source§

impl PartialEq for MovementMemory

Source§

fn eq(&self, other: &MovementMemory) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for MovementMemory

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MovementMemory

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.