use star::{StarItem, StarIterator}; use std::env; use std::fs::File; use std::io::BufReader; fn main() -> Result<(), Box> { let args: Vec = env::args().collect(); if args.len() != 2 { eprintln!("Usage: star-debug "); std::process::exit(1); } let file = File::open(&args[1])?; let reader = BufReader::new(file); let iter = StarIterator::new(reader); let mut nodes = 0; let mut records = 0; for item in iter.iter_tree() { let item = item?; match item { StarItem::Commit(c) => { println!("Commit:"); println!(" DID: {}", c.did); println!(" Rev: {}", c.rev); println!(" Root: {:?}", c.data); } StarItem::Node(_n) => { // print_node(&n); nodes += 1; } StarItem::Record { .. } => { // println!(" Record: key={}, cid={}", to_hex(&key), cid); records += 1; } } } println!("Tree contained {nodes} nodes, {records} records."); Ok(()) } // fn print_node(node: &StarMstNode) { // println!("Node:"); // if let Some(l) = node.l { // println!(" Left -> {}", l); // } // for (i, e) in node.e.iter().enumerate() { // print!(" Entry {}: key={}", i, to_hex(&e.k)); // if let Some(v) = e.v { // print!(", val={}", v); // } else { // print!(", val=(implicit)"); // } // if let Some(t) = e.t { // print!(", right->{}", t); // } // println!(); // } // } // fn to_hex(bytes: &[u8]) -> String { // let mut s = String::with_capacity(bytes.len() * 2); // for b in bytes { // use std::fmt::Write; // write!(&mut s, "{:02x}", b).unwrap(); // } // s // }