From dfe59cd14c9acf77dc7fa394ad3846c2c346cd77 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Tue, 3 Mar 2026 23:36:11 +0000 Subject: [PATCH] replace serde with facet across all crates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bough-core: serde → facet, toml deserialization via facet-toml - bough-typed-hash: serde → facet, serde_json → facet-json - bough-typed-hash-derive: remove generated serde::Serialize impl - Inline PhaseMetaConfig fields (flatten not needed) - Remove chrono dependency - LanguageId uses facet(rename) for short names (js/ts) --- Cargo.lock | 393 ++++++++++++--------- crates/bough-core/Cargo.toml | 4 +- crates/bough-core/SPEC.md | 59 +++- crates/bough-core/src/config.rs | 120 ++++--- crates/bough-core/src/file.rs | 3 +- crates/bough-typed-hash-derive/src/lib.rs | 9 +- crates/bough-typed-hash/Cargo.toml | 8 +- crates/bough-typed-hash/src/store.rs | 10 +- crates/bough-typed-hash/src/tests.rs | 13 +- crates/bough-typed-hash/src/unvalidated.rs | 16 +- 10 files changed, 352 insertions(+), 283 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0acaacbc..7563253e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,13 +12,10 @@ dependencies = [ ] [[package]] -name = "android_system_properties" -version = "0.1.5" +name = "allocator-api2" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "anstream" @@ -102,11 +99,11 @@ name = "bough-core" version = "0.0.0" dependencies = [ "bough-typed-hash", - "chrono", "clap", + "facet", + "facet-toml", "glob", "rand", - "serde", "tempfile", "toml", "tree-sitter", @@ -120,8 +117,8 @@ name = "bough-typed-hash" version = "0.0.0" dependencies = [ "bough-typed-hash-derive", - "serde", - "serde_json", + "facet", + "facet-json", "sha2", "tempfile", ] @@ -135,12 +132,6 @@ dependencies = [ "syn", ] -[[package]] -name = "bumpalo" -version = "3.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" - [[package]] name = "cc" version = "1.2.56" @@ -168,20 +159,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "chrono" -version = "0.4.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "serde", - "wasm-bindgen", - "windows-link", -] - [[package]] name = "clap" version = "4.5.60" @@ -229,10 +206,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "const-fnv1a-hash" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" [[package]] name = "cpufeatures" @@ -288,6 +265,154 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "facet" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98c578b0cf6efa3459c6ff5f9f67ddfa668ba778fdbf301a1ba6bb493bf32aba" +dependencies = [ + "autocfg", + "facet-core", + "facet-macros", +] + +[[package]] +name = "facet-core" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2c09e5a796b8989e7555cbe097ddd3c3ffa4c02392b9b4ad0d7cd48b1af5c2" +dependencies = [ + "autocfg", + "const-fnv1a-hash", + "iddqd", + "impls", +] + +[[package]] +name = "facet-dessert" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64092a2ececf59431c1b98561ba12e308c20185185fedc8c5396468e87573435" +dependencies = [ + "facet-core", + "facet-reflect", +] + +[[package]] +name = "facet-format" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b93a20a96d7dc1ab469896487f26f5c467b5b28c0448b4419fe8497ed1c6e5c" +dependencies = [ + "facet-core", + "facet-dessert", + "facet-path", + "facet-reflect", + "facet-solver", +] + +[[package]] +name = "facet-json" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cb1beadcaada7bbadd9856948061dbda047d8aad9eba1b8de1d2eec2fff9e5" +dependencies = [ + "facet", + "facet-core", + "facet-format", + "facet-reflect", + "memchr", +] + +[[package]] +name = "facet-macro-parse" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0ecddfa2b01f0ea083571f9cbb945222bc6603ce2c1cad9105eb8a432e09298" +dependencies = [ + "facet-macro-types", + "proc-macro2", + "quote", +] + +[[package]] +name = "facet-macro-types" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22ff06d4c4bb3cc6cfaf51d20c66444d7845ab047a7cd500b2677f01a9f6fd9" +dependencies = [ + "proc-macro2", + "quote", + "unsynn", +] + +[[package]] +name = "facet-macros" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cd4fe21b304e67937988fd88ef0907453a11921597fddff8ea8dc711575bfc7" +dependencies = [ + "facet-macros-impl", +] + +[[package]] +name = "facet-macros-impl" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b050ae34e587b27fa45e33720722be8ccc20a3d64f4560882cffae1ce65c564f" +dependencies = [ + "facet-macro-parse", + "facet-macro-types", + "proc-macro2", + "quote", + "strsim", + "unsynn", +] + +[[package]] +name = "facet-path" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ae380f4553db1a2ab33fb75035e7d86c178f384c4ded2e1681daec58cbbfc2" +dependencies = [ + "facet-core", +] + +[[package]] +name = "facet-reflect" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2469bdb237a3f3cac3077b784e86be88e379534ff9322d53b3d673e27bcb0988" +dependencies = [ + "facet-core", + "facet-path", + "hashbrown 0.16.1", + "regex", + "smallvec", +] + +[[package]] +name = "facet-solver" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e87fefb7fabe10278980588bb13bcfde4faeda4b3c29ae83c3c66efe0cad1a5" +dependencies = [ + "facet-core", + "facet-reflect", +] + +[[package]] +name = "facet-toml" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9c584d182d3345133c8360c7646c942e27f82031365d8dde32a425b460894f" +dependencies = [ + "facet-core", + "facet-format", + "facet-reflect", + "toml_parser", +] + [[package]] name = "fastrand" version = "2.3.0" @@ -306,6 +431,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "generic-array" version = "0.14.7" @@ -342,7 +473,7 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "foldhash", + "foldhash 0.1.5", ] [[package]] @@ -350,6 +481,11 @@ name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] [[package]] name = "heck" @@ -358,34 +494,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] -name = "iana-time-zone" -version = "0.1.65" +name = "id-arena" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" [[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" +name = "iddqd" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +checksum = "6b215e67ed1d1a4b1702acd787c487d16e4c977c5dcbcc4587bdb5ea26b6ce06" dependencies = [ - "cc", + "allocator-api2", + "equivalent", + "foldhash 0.2.0", + "hashbrown 0.16.1", + "rustc-hash", ] [[package]] -name = "id-arena" -version = "2.3.0" +name = "impls" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" +checksum = "7a46645bbd70538861a90d0f26c31537cdf1e44aae99a794fb75a664b70951bc" [[package]] name = "indexmap" @@ -411,16 +542,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" -[[package]] -name = "js-sys" -version = "0.3.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dc6f6450b3f6d4ed5b16327f38fed626d375a886159ca555bd7822c0c3a5a6" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - [[package]] name = "leb128fmt" version = "0.1.0" @@ -452,13 +573,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] -name = "num-traits" -version = "0.2.19" +name = "mutants" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] +checksum = "bc0287524726960e07b119cebd01678f852f147742ae0d925e6a520dca956126" [[package]] name = "once_cell" @@ -552,6 +670,12 @@ version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustix" version = "1.1.4" @@ -565,12 +689,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - [[package]] name = "semver" version = "1.0.27" @@ -584,7 +702,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", - "serde_derive", ] [[package]] @@ -647,6 +764,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "smallvec" +version = "2.0.0-alpha.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef784004ca8777809dcdad6ac37629f0a97caee4c685fcea805278d81dd8b857" + [[package]] name = "streaming-iterator" version = "0.1.9" @@ -718,6 +841,15 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + [[package]] name = "toml_write" version = "0.1.2" @@ -782,6 +914,17 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "unsynn" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501a7adf1a4bd9951501e5c66621e972ef8874d787628b7f90e64f936ef7ec0a" +dependencies = [ + "mutants", + "proc-macro2", + "rustc-hash", +] + [[package]] name = "utf8parse" version = "0.2.2" @@ -821,51 +964,6 @@ dependencies = [ "wit-bindgen", ] -[[package]] -name = "wasm-bindgen" -version = "0.2.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60722a937f594b7fde9adb894d7c092fc1bb6612897c46368d18e7a20208eff2" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac8c6395094b6b91c4af293f4c79371c163f9a6f56184d2c9a85f5a95f3950" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3fabce6159dc20728033842636887e4877688ae94382766e00b180abac9d60" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0e091bdb824da87dc01d967388880d017a0a9bc4f3bdc0d86ee9f9336e3bb5" -dependencies = [ - "unicode-ident", -] - [[package]] name = "wasm-encoder" version = "0.244.0" @@ -900,65 +998,12 @@ dependencies = [ "semver", ] -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.61.2" diff --git a/crates/bough-core/Cargo.toml b/crates/bough-core/Cargo.toml index 739693bb..065569bc 100644 --- a/crates/bough-core/Cargo.toml +++ b/crates/bough-core/Cargo.toml @@ -6,11 +6,11 @@ license.workspace = true [dependencies] bough-typed-hash = { path = "../bough-typed-hash" } -chrono = { version = "0.4", features = ["serde"] } clap = { version = "4.5.60", features = ["derive"] } +facet = "0.44" +facet-toml = "0.44" glob = "0.3" rand = "0.10.0" -serde = { version = "1", features = ["derive"] } toml = "0.8" tree-sitter = "0.26" tree-sitter-javascript = "0.25" diff --git a/crates/bough-core/SPEC.md b/crates/bough-core/SPEC.md index 640a48c7..a33223e8 100644 --- a/crates/bough-core/SPEC.md +++ b/crates/bough-core/SPEC.md @@ -84,31 +84,62 @@ Workspace should be reated by copying the matched files of Source::all_files core[workspace.bind] `Workplace::bind(dir: PathBuf, id: &WorkspaceId) -> Result` creates a new struct associated with an existing directory -core[workspacen.bind.validate-unchanged] +core[workspace.bind.validate-unchanged] Workspace::validate_unchanged() is called after bind to ensure it has not changed core[workspace.validate-unchanged] Workspace::validate_unchanged() checks that list and file contents of Base::files and Workspace::files are identicall - +## Phase - - +core[phase.root] +Phase holds &Root - - +core[phase.pwd] +Phase holds a twig called pwd - - +core[phase.env] +Phase holds a HashMap of env vars to apply - - +core[phase.cmd] +Phase::cmd is a Vec that will be run as a sub process - - +core[phase.timeout] +Phase::timeout is a TimeoutConfig - - +core[phase.run] +Phase::run() -> Result<_,_> runs Phase::cmd + +core[phase.run.pwd] +Phase::run runs the command in File { root, pwd } + +core[phase.run.env] +Phase::run runs the command with the secified env vars + +core[phase.run.timeout] +Phase::run stops the command if it extends the provided timeout + +core[phase.run.timeout.absolute] +Phase::run stops the command if it extends the provided absolute timeout + +core[phase.run.timeout.relative] +Phase::run takes an optional Duration. it stops the command if this Duration is defined, and it extends the provided relative `timeout * provided_duration` + +core[phase.out] +`Phase::run -> Result` + +core[phase.out.stdio] +PhaseOutcome should retain all stdout and stderr from the command + +core[phase.out.exit] +PhaseOutcome should contain the exit code of the command, non-zero should return Ok(), not Err + +core[phase.out.duration] +PhaseOutcome should contain the duration time of the command + +## Mutant + +## Mutation diff --git a/crates/bough-core/src/config.rs b/crates/bough-core/src/config.rs index 5d0f22ff..e30b0a2c 100644 --- a/crates/bough-core/src/config.rs +++ b/crates/bough-core/src/config.rs @@ -1,46 +1,34 @@ -use serde::{Deserialize, Serialize}; +use facet::Facet; use std::collections::HashMap; use std::path::PathBuf; -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "PascalCase")] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Facet)] +#[facet(rename_all = "PascalCase")] +#[repr(u8)] pub enum Outcome { #[default] Missed, Caught, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, clap::ValueEnum, bough_typed_hash::HashInto)] -#[serde(rename_all = "lowercase")] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Facet, clap::ValueEnum, bough_typed_hash::HashInto)] +#[facet(rename_all = "lowercase")] +#[repr(u8)] pub enum LanguageId { - #[serde(alias = "js")] + #[facet(rename = "js")] #[value(alias = "js")] Javascript, - #[serde(alias = "ts")] + #[facet(rename = "ts")] #[value(alias = "ts")] Typescript, } -fn default_threads() -> u32 { - 1 -} -fn default_bough_dir() -> PathBuf { - PathBuf::from("./.bough") -} - -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] -pub struct PhaseMetaConfig { +#[derive(Debug, Default, Clone, PartialEq, Facet)] +#[facet(default)] +pub struct PhaseConfig { pub(crate) pwd: Option, pub(crate) timeout: TimeoutConfig, pub(crate) env: HashMap, -} - -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] -pub struct PhaseConfig { - #[serde(flatten)] - pub(crate) meta: PhaseMetaConfig, pub(crate) command: String, } @@ -50,15 +38,16 @@ impl PhaseConfig { } } -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] +#[derive(Debug, Default, Clone, PartialEq, Facet)] +#[facet(default)] pub struct TimeoutConfig { pub(crate) absolute: Option, pub(crate) relative: Option, } -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, clap::ValueEnum)] -#[serde(rename_all = "lowercase")] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Facet, clap::ValueEnum)] +#[facet(rename_all = "lowercase")] +#[repr(u8)] pub enum OrderingConfig { #[default] Random, @@ -68,72 +57,78 @@ pub enum OrderingConfig { NewestFirst, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Facet)] pub struct TestIdsConfig { pub(crate) get_all: String, pub(crate) get_failed: String, } -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] +#[derive(Debug, Default, Clone, PartialEq, Facet)] +#[facet(default)] pub struct MutateLanguageConfig { pub(crate) files: FileSourceConfig, pub(crate) mutants: MutantFilterConfig, } -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] +#[derive(Debug, Default, Clone, PartialEq, Facet)] +#[facet(default)] pub struct FileSourceConfig { pub(crate) include: Vec, pub(crate) exclude: Vec, pub(crate) ignore_files: Vec, } -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] +#[derive(Debug, Default, Clone, PartialEq, Facet)] +#[facet(default)] pub struct MutantFilterConfig { pub(crate) skip: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(untagged)] +#[derive(Debug, Clone, PartialEq, Facet)] +#[facet(untagged)] +#[repr(C)] pub enum MutantSkipConfig { Query { query: String }, Kind { kind: HashMap }, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(default)] +#[derive(Debug, Clone, PartialEq, Facet)] pub struct Config { - #[serde(default = "default_threads")] + #[facet(default = 1u32)] pub(crate) threads: u32, - #[serde(default = "default_bough_dir")] + #[facet(default = PathBuf::from("./.bough"))] pub(crate) bough_dir: PathBuf, - #[serde(skip)] + #[facet(skip, default = PathBuf::new())] pub(crate) source_dir: PathBuf, + #[facet(default)] pub(crate) ordering: OrderingConfig, + #[facet(default = Outcome::Caught)] pub(crate) treat_timeouts_as: Outcome, pub(crate) test_ids: Option, - #[serde(flatten)] - pub(crate) meta_defaults: PhaseMetaConfig, + pub(crate) pwd: Option, + #[facet(default)] + pub(crate) timeout: TimeoutConfig, + pub(crate) env: HashMap, pub(crate) init: Option, pub(crate) reset: Option, pub(crate) test: Option, + #[facet(default)] pub(crate) files: FileSourceConfig, - #[serde(default)] pub(crate) mutate: HashMap, } impl Default for Config { fn default() -> Self { Self { - threads: default_threads(), - bough_dir: default_bough_dir(), + threads: 1, + bough_dir: PathBuf::from("./.bough"), source_dir: PathBuf::default(), ordering: OrderingConfig::default(), treat_timeouts_as: Outcome::Caught, test_ids: None, - meta_defaults: PhaseMetaConfig::default(), + pwd: None, + timeout: TimeoutConfig::default(), + env: HashMap::new(), init: None, reset: None, test: None, @@ -184,7 +179,8 @@ impl ConfigBuilder { // core[impl config.source-dir] pub fn build(self) -> Result { - let mut config = Config::deserialize(self.value).map_err(ConfigError::Deserialize)?; + let toml_str = toml::to_string(&self.value).map_err(|e| ConfigError::Serialize(e.to_string()))?; + let mut config: Config = facet_toml::from_str(&toml_str).map_err(|e| ConfigError::Deserialize(e.to_string()))?; config.source_dir = self.source_dir; Ok(config) } @@ -192,13 +188,15 @@ impl ConfigBuilder { #[derive(Debug)] pub enum ConfigError { - Deserialize(toml::de::Error), + Deserialize(String), + Serialize(String), } impl std::fmt::Display for ConfigError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { ConfigError::Deserialize(e) => write!(f, "failed to deserialize config: {e}"), + ConfigError::Serialize(e) => write!(f, "failed to serialize config: {e}"), } } } @@ -260,7 +258,7 @@ files.include = ["src/**/*.ts"] #[test] fn deserialize_ideal_config() { - let config: Config = toml::from_str(IDEAL_CONFIG).expect("failed to parse ideal config"); + let config: Config = facet_toml::from_str(IDEAL_CONFIG).expect("failed to parse ideal config"); assert_eq!(config.threads, 1); assert_eq!(config.bough_dir, PathBuf::from("./.bough")); @@ -268,13 +266,13 @@ files.include = ["src/**/*.ts"] assert_eq!(config.treat_timeouts_as, Outcome::Missed); let init = config.init.as_ref().unwrap(); - assert_eq!(init.meta.pwd, Some(PathBuf::from("./examples/vitest"))); + assert_eq!(init.pwd, Some(PathBuf::from("./examples/vitest"))); assert_eq!(init.command, "npm install"); let test = config.test.as_ref().unwrap(); - assert_eq!(test.meta.timeout.absolute, Some(30)); - assert_eq!(test.meta.timeout.relative, Some(3)); - assert_eq!(test.meta.env["NODE_ENV"], "production"); + assert_eq!(test.timeout.absolute, Some(30)); + assert_eq!(test.timeout.relative, Some(3)); + assert_eq!(test.env["NODE_ENV"], "production"); assert_eq!(test.command, "npx run test"); let js_mutate = &config.mutate[&LanguageId::Javascript]; @@ -286,7 +284,7 @@ files.include = ["src/**/*.ts"] #[test] fn deserialize_minimal_config() { let config: Config = - toml::from_str(MINIMAL_CONFIG).expect("failed to parse minimal config"); + facet_toml::from_str(MINIMAL_CONFIG).expect("failed to parse minimal config"); assert_eq!(config.threads, 1); assert_eq!(config.bough_dir, PathBuf::from("./.bough")); @@ -297,9 +295,9 @@ files.include = ["src/**/*.ts"] let test = config.test.as_ref().unwrap(); assert_eq!(test.command, "npx vitest run"); - assert_eq!(test.meta.pwd, None); - assert!(test.meta.env.is_empty()); - assert_eq!(test.meta.timeout, TimeoutConfig::default()); + assert_eq!(test.pwd, None); + assert!(test.env.is_empty()); + assert_eq!(test.timeout, TimeoutConfig::default()); let ts_mutate = &config.mutate[&LanguageId::Typescript]; assert_eq!(ts_mutate.files.include, vec!["src/**/*.ts"]); @@ -352,7 +350,7 @@ files.include = ["src/**/*.ts"] FOO = "bar" "#, ); - assert_eq!(config.test.as_ref().unwrap().meta.env["FOO"], "bar"); + assert_eq!(config.test.as_ref().unwrap().env["FOO"], "bar"); } // core[verify config.partials] @@ -365,7 +363,7 @@ files.include = ["src/**/*.ts"] #[test] fn defaults_are_sane() { - let config: Config = toml::from_str("").expect("empty config should parse"); + let config: Config = facet_toml::from_str("").expect("empty config should parse"); assert_eq!(config.threads, 1); assert_eq!(config.bough_dir, PathBuf::from("./.bough")); assert!(config.init.is_none() && config.reset.is_none() && config.test.is_none()); diff --git a/crates/bough-core/src/file.rs b/crates/bough-core/src/file.rs index 0093e89b..981aafb9 100644 --- a/crates/bough-core/src/file.rs +++ b/crates/bough-core/src/file.rs @@ -1,5 +1,4 @@ use bough_typed_hash::{HashInto, TypedHashable}; -use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; #[derive(bough_typed_hash::TypedHash)] @@ -23,7 +22,7 @@ pub struct File<'a, R: Root> { } // core[impl file.twig] -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] pub struct Twig(PathBuf); impl std::fmt::Display for Error { diff --git a/crates/bough-typed-hash-derive/src/lib.rs b/crates/bough-typed-hash-derive/src/lib.rs index 3c137686..7534eaf3 100644 --- a/crates/bough-typed-hash-derive/src/lib.rs +++ b/crates/bough-typed-hash-derive/src/lib.rs @@ -74,9 +74,7 @@ pub fn derive_hash_into(input: TokenStream) -> TokenStream { /// Derives a full `TypedHash` implementation on a newtype wrapping `[u8; 32]`. /// /// Generates: `TypedHash`, `HashInto`, `TypedHashable`, `Display` -/// (hex), `Serialize` (hex string), `Debug`, `Clone`, `PartialEq`, `Eq`, `Hash`. -/// -/// Does **not** generate `FromStr`, `From<[u8; 32]>`, or `Deserialize`. +/// (hex), `Debug`, `Clone`, `PartialEq`, `Eq`, `Hash`. #[proc_macro_derive(TypedHash)] pub fn derive_typed_hash(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); @@ -168,11 +166,6 @@ pub fn derive_typed_hash(input: TokenStream) -> TokenStream { } } - impl serde::Serialize for #name { - fn serialize(&self, serializer: S) -> ::std::result::Result { - serializer.serialize_str(&self.to_string()) - } - } }; expanded.into() diff --git a/crates/bough-typed-hash/Cargo.toml b/crates/bough-typed-hash/Cargo.toml index 0f867002..8eab2116 100644 --- a/crates/bough-typed-hash/Cargo.toml +++ b/crates/bough-typed-hash/Cargo.toml @@ -6,14 +6,14 @@ license.workspace = true [features] default = [] -disk = ["serde_json"] +disk = ["facet-json"] [dependencies] sha2 = "0.10" -serde = { version = "1", features = ["derive"] } -serde_json = { version = "1", optional = true } +facet = "0.44" +facet-json = { version = "0.44", optional = true } bough-typed-hash-derive = { path = "../bough-typed-hash-derive" } [dev-dependencies] -serde_json = "1" +facet-json = "0.44" tempfile = "3" diff --git a/crates/bough-typed-hash/src/store.rs b/crates/bough-typed-hash/src/store.rs index 97986d71..c0c8d66b 100644 --- a/crates/bough-typed-hash/src/store.rs +++ b/crates/bough-typed-hash/src/store.rs @@ -138,7 +138,7 @@ impl HashStore for ChainStore<'_, T> { /// File-backed hash store. Values stored as `{hash_hex}.json` in a directory. /// -/// Requires the `disk` feature. Values must impl `Serialize + DeserializeOwned`. +/// Requires the `disk` feature. Values must impl `Facet`. /// Scans the directory at construction to build an index. Values are lazily /// loaded and cached on first access via interior mutability. #[cfg(feature = "disk")] @@ -154,7 +154,7 @@ struct DiskEntry { } #[cfg(feature = "disk")] -impl DiskHashStore { +impl facet::Facet<'a>> DiskHashStore { /// Create a store backed by `dir`. Scans existing `*.json` files to build the index. pub fn new(dir: std::path::PathBuf) -> Self { let mut entries = Vec::new(); @@ -181,14 +181,14 @@ impl DiskHash } #[cfg(feature = "disk")] -impl HashStore for DiskHashStore { +impl facet::Facet<'a>> HashStore for DiskHashStore { fn get(&self, hash: &T::Hash) -> Option<&T> { let mut entries = self.entries.borrow_mut(); let idx = entries.iter().position(|e| e.hash.as_bytes() == hash.as_bytes())?; if entries[idx].value.is_none() { let path = self.hash_path(hash); let data = std::fs::read_to_string(&path).ok()?; - let value: T = serde_json::from_str(&data).ok()?; + let value: T = facet_json::from_str(&data).ok()?; entries[idx].value = Some(value); } drop(entries); @@ -201,7 +201,7 @@ impl HashStor fn insert(&mut self, value: T) { let hash = raw_hash(&value); std::fs::create_dir_all(&self.dir).expect("failed to create store directory"); - let json = serde_json::to_string_pretty(&value).expect("failed to serialize"); + let json = facet_json::to_string(&value).expect("failed to serialize"); std::fs::write(self.hash_path(&hash), json).expect("failed to write hash file"); let mut entries = self.entries.borrow_mut(); if let Some(entry) = entries.iter_mut().find(|e| e.hash.as_bytes() == hash.as_bytes()) { diff --git a/crates/bough-typed-hash/src/tests.rs b/crates/bough-typed-hash/src/tests.rs index 0db0a1b5..b840c27f 100644 --- a/crates/bough-typed-hash/src/tests.rs +++ b/crates/bough-typed-hash/src/tests.rs @@ -66,10 +66,11 @@ fn typed_hash_clone_eq() { } #[test] -fn typed_hash_serialize() { +fn typed_hash_display_format() { let h = TestHash::from_raw([0xab; 32]); - let json = serde_json::to_string(&h).unwrap(); - assert_eq!(json, format!("\"{}\"", h)); + let displayed = h.to_string(); + assert_eq!(displayed.len(), 64); + assert!(displayed.chars().all(|c| c == 'a' || c == 'b')); } #[test] @@ -220,8 +221,7 @@ fn unvalidated_hash_roundtrip() { let h = w.hash(&mut store).unwrap(); let hex = h.to_string(); - let json = format!("\"{hex}\""); - let unvalidated: UnvalidatedHash = serde_json::from_str(&json).unwrap(); + let unvalidated = UnvalidatedHash::new(hex); let validated = unvalidated.validate::(&store).unwrap(); assert_eq!(validated, h); } @@ -361,9 +361,8 @@ fn hash_std_trait_impls() { #[cfg(feature = "disk")] mod disk_tests { use super::*; - use serde::{Deserialize, Serialize}; - #[derive(Clone, Serialize, Deserialize, TypedHashable)] + #[derive(Clone, facet::Facet, TypedHashable)] pub struct DiskItem { pub val: u32, } diff --git a/crates/bough-typed-hash/src/unvalidated.rs b/crates/bough-typed-hash/src/unvalidated.rs index e5a4bae6..d57f0998 100644 --- a/crates/bough-typed-hash/src/unvalidated.rs +++ b/crates/bough-typed-hash/src/unvalidated.rs @@ -1,10 +1,9 @@ use crate::{HashError, HashStore, TypedHash, TypedHashable}; -use serde::{Deserialize, Serialize}; -/// Serde intermediate for deserializing hashes without store validation. +/// Intermediate type for deserializing hashes without store validation. /// -/// `TypedHash` does not implement `Deserialize` — deserialized hashes would -/// bypass store validation. Use `UnvalidatedHash` as the serde target, then +/// `TypedHash` does not implement deserialization — deserialized hashes would +/// bypass store validation. Use `UnvalidatedHash` as the target, then /// call [`.validate()`](UnvalidatedHash::validate) with a store. /// /// # Example @@ -20,14 +19,19 @@ use serde::{Deserialize, Serialize}; /// let hash = record.hash(&mut store).unwrap(); /// let hex = hash.to_string(); /// -/// let unvalidated: UnvalidatedHash = serde_json::from_str(&format!("\"{hex}\"")).unwrap(); +/// let unvalidated = UnvalidatedHash::new(hex); /// let validated = unvalidated.validate::(&store).unwrap(); /// assert_eq!(validated.as_bytes(), hash.as_bytes()); /// ``` -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, facet::Facet)] +#[facet(transparent)] pub struct UnvalidatedHash(String); impl UnvalidatedHash { + pub fn new(hex: String) -> Self { + Self(hex) + } + /// Validate against a store, supporting both full hex and unique prefixes. pub fn validate( self, -- knotmirror 0.0.1