#trail #primitive #values #save #variables #restore #backtrack

search_trail

A simple manager of variables that can save and restore their values

3 releases

0.1.2 Oct 19, 2023
0.1.1 Sep 29, 2023
0.1.0 Mar 8, 2023

#544 in Data structures

35 downloads per month
Used in schlandals

MIT license

27KB
415 lines

search_trail

search_trail provides a data structure to manage values of primitive types. It means that you're able to

  • create a new managed resource (of type usize, isize, f32, etc.)
  • Save the state of the manager (i.e. a "snapshot" of all the values of the managed resources)
  • Restore the manager to its previous state (i.e. set the values of the managed resources to the previous snapshot)

The code was originally developped by @xgillard on maxi-cp-rs. This repo only adds the support for other type.

Example

use search_trail::{StateManager, SaveAndRestore, UsizeManager};

fn main() {
 let mut mgr = StateManager::default();
 let n = mgr.manage_usize(0);
 assert_eq!(0, mgr.get_usize(n));
 
 mgr.save_state();
 
 mgr.set_usize(n, 20);
 assert_eq!(20, mgr.get_usize(n));
 
 mgr.save_state();

 mgr.set_usize(n, 42);
 assert_eq!(42, mgr.get_usize(n));
 
 mgr.restore_state();
 assert_eq!(20, mgr.get_usize(n));
 
 mgr.restore_state();
 assert_eq!(0, mgr.get_usize(n));
}

Dependencies