diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..2e06d15 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,2 @@ +allow-unwrap-in-consts = true +allow-unwrap-in-tests = true diff --git a/.github/workflows/hybrid-array.yml b/.github/workflows/hybrid-array.yml index bbf3f32..45e7cf5 100644 --- a/.github/workflows/hybrid-array.yml +++ b/.github/workflows/hybrid-array.yml @@ -53,7 +53,7 @@ jobs: - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.85.0 + toolchain: 1.94.0 components: clippy - run: cargo clippy --all-targets --all-features -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index ee8d9c4..1bd2e8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3" +[[package]] +name = "cobs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror", +] + [[package]] name = "ctutils" version = "0.4.0" @@ -29,6 +38,18 @@ dependencies = [ "cmov", ] +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "hybrid-array" version = "0.4.9" @@ -36,6 +57,7 @@ dependencies = [ "arbitrary", "bytemuck", "ctutils", + "postcard", "serde", "subtle", "typenum", @@ -43,6 +65,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "postcard" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -68,6 +102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", + "serde_derive", ] [[package]] @@ -107,6 +142,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "typenum" version = "1.19.0" diff --git a/Cargo.toml b/Cargo.toml index 186674c..6994580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,9 @@ subtle = { version = "2", optional = true, default-features = false, features = zeroize = { version = "1.8", optional = true, default-features = false } zerocopy = { version = "0.8", optional = true, features = ["derive"] } +[dev-dependencies] +postcard = { version = "1", default-features = false, features = ["alloc"] } + [features] alloc = [] extra-sizes = [] diff --git a/src/serde.rs b/src/serde.rs index 4647581..63bba91 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -69,3 +69,17 @@ where seq.end() } } + +#[cfg(test)] +mod tests { + use crate::{Array, sizes::U3}; + type A = Array; + + #[test] + fn round_trip() { + let example: A = Array([1, 2, 3]); + let bytes = postcard::to_allocvec(&example).unwrap(); + let deserialized: A = postcard::from_bytes(&bytes).unwrap(); + assert_eq!(example, deserialized); + } +}