| Crates.io | indentsort |
| lib.rs | indentsort |
| version | 0.1.2 |
| created_at | 2024-08-19 15:27:47.819455+00 |
| updated_at | 2025-06-15 08:26:15.209059+00 |
| description | Structure-preserving sorting of arbitrary indented text |
| homepage | |
| repository | https://github.com/mkforsb/indentsort-rs |
| max_upload_size | |
| id | 1344005 |
| size | 19,006 |
This crate provides a function indentsort which performs structure-preserving sorting of
arbitrary text that is structured using indentation.
// input // output
foo { foo {
b, a: 0,
c: { b,
9, ---> c: {
1, 1,
}, 9,
a: 0, },
} }
Some details to note:
foo{} and bar{} ends up at the bottom
and how there is no longer a comma separating the two blocks.use indentsort::{indentsort, Options};
let sorted = indentsort(Options::Default, r#"
foo {
b,
c,
a,
},
bar {
xyz: 123,
nums: [
3,
2,
1,
],
}"#
);
assert_eq!(sorted.join("\n"),
r#"bar {
nums: [
1,
2,
3,
],
xyz: 123,
}
foo {
a,
b,
c,
},"#
);
indentsort provides a cheap and cheerful way to do equality testing on nested,
indentation-structured text where the ordering of elements is not guaranteed. The original
motivating example was a need for equality testing over a complex Rust struct where deriving
PartialEq, Eq was not an option, but Debug was available for pretty-printing.
Equality testing of complex objects by string comparison is likely to be a bad idea in general, so for production you probably want to parse your text properly instead of using something like this.