diffo 0.2.0

Semantic diffing for Rust structs via serde
Documentation
//! Demonstrates the three sequence diffing algorithms.

use diffo::{diff_with, DiffConfig, SequenceDiffAlgorithm};
use serde::Serialize;

#[derive(Serialize)]
struct Data {
    numbers: Vec<i32>,
    users: Vec<String>,
}

fn main() {
    println!("=== Sequence Diffing Algorithms Demo ===\n");

    // Sample data with insertion in the middle
    let old = Data {
        numbers: vec![1, 2, 3, 4, 5],
        users: vec!["alice".into(), "bob".into(), "charlie".into()],
    };

    let new = Data {
        numbers: vec![1, 2, 99, 3, 4, 5], // 99 inserted at index 2
        users: vec![
            "alice".into(),
            "david".into(),
            "bob".into(),
            "charlie".into(),
        ],
    };

    // 1. IndexBased (default) - Simple index-by-index comparison
    println!("1. IndexBased Algorithm (O(n), default)");
    println!("   Best for: Simple changes, backward compatibility");
    let config = DiffConfig::new().default_sequence_algorithm(SequenceDiffAlgorithm::IndexBased);
    let diff = diff_with(&old, &new, &config).unwrap();
    println!("   Changes detected: {}", diff.len());
    for (path, change) in diff.changes() {
        println!("   {} -> {:?}", path, change);
    }
    println!();

    // 2. Myers - Optimal edit distance
    println!("2. Myers Algorithm (O(ND), optimal)");
    println!("   Best for: Finding minimal edit distance");
    let config = DiffConfig::new().default_sequence_algorithm(SequenceDiffAlgorithm::Myers);
    let diff = diff_with(&old, &new, &config).unwrap();
    println!("   Changes detected: {}", diff.len());
    for (path, change) in diff.changes() {
        println!("   {} -> {:?}", path, change);
    }
    println!();

    // 3. Patience - Human-intuitive diffing
    println!("3. Patience Algorithm (O(N log N), intuitive)");
    println!("   Best for: Code diffs, reorderings, human review");
    let config = DiffConfig::new().default_sequence_algorithm(SequenceDiffAlgorithm::Patience);
    let diff = diff_with(&old, &new, &config).unwrap();
    println!("   Changes detected: {}", diff.len());
    for (path, change) in diff.changes() {
        println!("   {} -> {:?}", path, change);
    }
    println!();

    // 4. Per-path configuration
    println!("4. Per-Path Algorithm Configuration");
    println!("   Use different algorithms for different paths");
    let config = DiffConfig::new()
        .sequence_algorithm("numbers", SequenceDiffAlgorithm::Myers)
        .sequence_algorithm("users", SequenceDiffAlgorithm::Patience);

    let diff = diff_with(&old, &new, &config).unwrap();
    println!("   Changes detected: {}", diff.len());
    println!("   numbers: Myers (optimal)");
    println!("   users: Patience (intuitive)");
    for (path, change) in diff.changes() {
        println!("   {} -> {:?}", path, change);
    }
}