stitcher

Crates.iostitcher
lib.rsstitcher
version0.2.1
created_at2025-04-19 21:15:45.843422+00
updated_at2025-04-19 23:51:30.123862+00
descriptionstitcher provides an ergonomic syntax for declaring deeply nested Rust data structures inline — useful for tests and fixtures where writing raw constructors would be noisy or tedious.
homepagehttps://crates.io/crates/stitcher
repositoryhttps://github.com/jameslkingsley/stitcher
max_upload_size
id1641159
size24,301
James Kingsley (jameslkingsley)

documentation

https://docs.rs/stitcher

README

stitcher

stitcher provides an ergonomic syntax for declaring deeply nested Rust data structures inline — useful for tests and fixtures where writing raw constructors would be noisy or tedious.

cargo add --dev stitcher

🔧 Features

  • Declarative, readable inline data syntax
  • Fully Serde-compatible
  • Supports recursive partial defaults
  • Allows copying other values with dot-notation syntax
  • Support variable injection with $ syntax

✨ Example

use stitcher::stitch;
use serde::{Serialize, Deserialize};

let timezone = "Europe/London";

let scenario = stitch!(Scenario {
    schedules: [
        {
            name: "Morning Yoga",
            location: {
                name: "Studio 1",
                tz: $timezone,
            }
        },
        {
            name: "Evening Spin",
            location: schedules[0].location,
        }
    ]
});

#[derive(Debug, Default, Serialize, Deserialize)]
struct Location {
    name: String,
    tz: String,
}

#[derive(Debug, Default, Serialize, Deserialize)]
struct Schedule {
    name: String,
    location: Location,
}

#[derive(Debug, Default, Serialize, Deserialize)]
struct Scenario {
    schedules: Vec<Schedule>,
}
Commit count: 0

cargo fmt