Expand description
§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>,
}
Macros§
- stitch
- The
stitch!
macro.
Functions§
- deep_
merge - Recursively merges values from
over
intobase
. - from_
stitch_ input - Constructs a type
T
from a stitched JSON value, applying recursive defaults and resolving internal references. - resolve_
refs_ in_ place - Recursively resolves all
__ref__...
string markers indata
, replacing them with actual values fromroot
.