search_trail

Crates.iosearch_trail
lib.rssearch_trail
version0.1.3
sourcesrc
created_at2023-03-08 15:00:24.566231
updated_at2024-05-06 13:23:52.29153
descriptionA simple manager of variables that can save and restore their values
homepage
repositoryhttps://github.com/AlexandreDubray/search-trail-rs
max_upload_size
id804696
size27,236
Quack (AlexandreDubray)

documentation

README

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));
}
Commit count: 13

cargo fmt