use ferrotype::Ferrotype;
fn main() {
println!("=== Ferrotype Features Example ===\n");
let mut snapshot = Ferrotype::new();
snapshot.add("Title", "Feature showcase example".to_string());
#[derive(Debug)]
#[allow(unused)]
struct ExampleData {
name: String,
values: Vec<i32>,
}
let data = ExampleData {
name: "test data".to_string(),
values: vec![1, 2, 3, 4, 5],
};
snapshot.add_debug("Debug Data", &data);
#[cfg(feature = "hex")]
{
println!("Feature 'hex' is enabled:");
let binary_data = b"Hello, World! \x00\x01\x02\x03\xFF\xFE\xFD";
snapshot.add_hex("Binary Data", binary_data);
let packet_data: Vec<u8> = (0..64).collect();
snapshot.add_hex("Network Packet", &packet_data);
println!("✓ Added hex dumps\n");
}
#[cfg(not(feature = "hex"))]
{
println!("Feature 'hex' is not enabled");
println!(" Run with: cargo run --example features --features hex\n");
}
#[cfg(feature = "tokenstream")]
{
println!("Feature 'tokenstream' is enabled:");
let code = r#"
fn calculate(x: i32, y: i32) -> i32 {
let result = x + y;
println!("Result: {}", result);
result
}
"#;
if let Ok(tokens) = code.parse::<proc_macro2::TokenStream>() {
snapshot.add_token_stream("Generated Code", &tokens);
println!("✓ Added formatted Rust code\n");
}
}
#[cfg(not(feature = "tokenstream"))]
{
println!("Feature 'tokenstream' is not enabled");
println!(
" Run with: cargo run --example features --features tokenstream\n"
);
}
#[cfg(feature = "anstream")]
{
println!("Feature 'anstream' is enabled:");
let colored_output = "\x1b[32mSUCCESS\x1b[0m: All tests \x1b[1;32mpassed\x1b[0m! \x1b[31mErrors: 0\x1b[0m";
snapshot.add_strip_str("Test Output", colored_output.to_string());
let terminal_output = "Loading\x08\x08\x08\x08\x08\x08\x08Done! \x1b[2K\x1b[1A\x1b[32m✓\x1b[0m Complete";
snapshot.add_strip_str("Terminal Progress", terminal_output.to_string());
println!("✓ Added content with ANSI codes stripped\n");
}
#[cfg(not(feature = "anstream"))]
{
println!("Feature 'anstream' is not enabled");
println!(" Run with: cargo run --example features --features anstream\n");
}
#[cfg(feature = "bluegum")]
{
println!("Feature 'bluegum' is enabled:");
#[derive(Debug)]
struct TreeNode {
name: String,
children: Vec<TreeNode>,
}
impl bluegum::Bluegum for TreeNode {
fn node(&self, builder: &mut bluegum::Builder) {
builder.name(&self.name);
for (i, child) in self.children.iter().enumerate() {
builder.add_node(&format!("child_{i}"), child);
}
}
}
impl bluegum::BluegumWithState<()> for TreeNode {}
let tree = TreeNode {
name: "Root".to_string(),
children: vec![
TreeNode {
name: "Branch A".to_string(),
children: vec![
TreeNode {
name: "Leaf 1".to_string(),
children: vec![],
},
TreeNode {
name: "Leaf 2".to_string(),
children: vec![],
},
],
},
TreeNode {
name: "Branch B".to_string(),
children: vec![TreeNode {
name: "Leaf 3".to_string(),
children: vec![],
}],
},
],
};
snapshot.add_bluegum("Tree Structure", &tree);
snapshot.add_bluegum_builder_with("Custom Tree", |b| {
b.name("CustomRoot")
.field("version", "1.0")
.field("status", "active");
});
println!("✓ Added tree visualizations\n");
}
#[cfg(not(feature = "bluegum"))]
{
println!("Feature 'bluegum' is not enabled");
println!(" Run with: cargo run --example features --features bluegum\n");
}
println!("=== Complete Snapshot ===");
snapshot.print();
println!("=========================\n");
println!("Feature Summary:");
println!(
" hex: {}",
if cfg!(feature = "hex") { "✓" } else { "✗" }
);
println!(
" tokenstream: {}",
if cfg!(feature = "tokenstream") {
"✓"
} else {
"✗"
}
);
println!(
" anstream: {}",
if cfg!(feature = "anstream") {
"✓"
} else {
"✗"
}
);
println!(
" bluegum: {}",
if cfg!(feature = "bluegum") {
"✓"
} else {
"✗"
}
);
println!("\nTo enable all features, run:");
println!(" cargo run --example features --all-features");
}