Skip to content

Commit

Permalink
Add packable BTreeSet impls and BTreeSetPrefix (#69)
Browse files Browse the repository at this point in the history
* Add BTreeSet impls and BTreeSetPrefix

* version

* fix derive package

* fix feature gates

* add tests and cleanup features

* Fix tests

* more feature refactors

* docs

* nits

* oop

* copyrights

* comment

* Fix test

---------

Co-authored-by: Thibault Martinez <thibault@iota.org>
  • Loading branch information
DaughterOfMars and thibault-martinez authored Sep 15, 2023
1 parent b3089cf commit cfea534
Show file tree
Hide file tree
Showing 96 changed files with 577 additions and 163 deletions.
2 changes: 1 addition & 1 deletion packable/packable-derive-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "tests"
path = "tests/lib.rs"

[dev-dependencies]
packable = { version = "=0.8.1", path = "../packable", default-features = false }
packable = { version = "=0.8.2", path = "../packable", default-features = false }

rustversion = { version = "1.0.9", default-features = false }
trybuild = { version = "1.0.71", default-features = false, features = [ "diff" ] }
Expand Down
2 changes: 1 addition & 1 deletion packable/packable-derive-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports, unreachable_patterns)]

use packable::{error::UnknownTagError, Packable};

use core::convert::Infallible;

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
#[packable(tag_type = u8)]
#[packable(unpack_error = UnknownTagError<u8>)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::{error::UnknownTagError, Packable};

use core::convert::Infallible;

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
#[packable(tag_type = u8)]
#[packable(unpack_error = UnknownTagError<u8>)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use core::convert::Infallible;

use packable::{
error::UnpackErrorExt,
error::{UnknownTagError, UnpackError},
error::{UnknownTagError, UnpackError, UnpackErrorExt},
packer::Packer,
unpacker::Unpacker,
Packable,
};

use core::convert::Infallible;

#[derive(Debug)]
pub struct PickyError(u8);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0308]: mismatched types
--> tests/fail/invalid_field_type_verify_with.rs:33:10
--> tests/fail/invalid_field_type_verify_with.rs:32:10
|
33 | #[derive(Packable)]
32 | #[derive(Packable)]
| ^^^^^^^^
| |
| expected `&u64`, found `&u8`
Expand All @@ -10,8 +10,8 @@ error[E0308]: mismatched types
= note: expected reference `&u64`
found reference `&u8`
note: function defined here
--> tests/fail/invalid_field_type_verify_with.rs:25:4
--> tests/fail/invalid_field_type_verify_with.rs:24:4
|
25 | fn verify_value<const VERIFY: bool>(&value: &u64, _: &()) -> Result<(), PickyError> {
24 | fn verify_value<const VERIFY: bool>(&value: &u64, _: &()) -> Result<(), PickyError> {
| ^^^^^^^^^^^^ ------------
= note: this error originates in the derive macro `Packable` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = Impossible, with = Impossible::new)]
pub struct Point {
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/fail/invalid_tag_enum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::{error::UnknownTagError, Packable};

use core::convert::Infallible;

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
#[packable(tag_type = u8)]
#[packable(unpack_error = UnknownTagError<u8>)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(tag_type = [u8; 32])]
#[packable(unpack_error = Infallible)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = 1)]
pub struct Point {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/fail/missing_tag_enum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(tag_type = u32)]
#[packable(unpack_error = Infallible)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = Infallible)]
pub enum OptI32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports, unreachable_patterns)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

struct NonPackable;

#[derive(Packable)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ error[E0277]: the trait bound `NonPackable: packable::Packable` is not satisfied
| ^^^^^^^^ the trait `packable::Packable` is not implemented for `NonPackable`
|
= help: the following other types implement trait `packable::Packable`:
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
(A, B, C, D, E, F, G)
(A, B, C, D, E, F, G, H)
(A, B, C, D, E, F, G, H, I)
and 28 others
bool
i8
i16
i32
i64
i128
u8
u16
and $N others
= note: this error originates in the derive macro `Packable` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/fail/union.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = Infallible)]
pub union MaybeInt {
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/fail/unknown_ident.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unknown_ident = true)]
pub struct Unit;
Expand Down
4 changes: 2 additions & 2 deletions packable/packable-derive-test/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{ffi::OsStr, fs::read_dir, path::Path};
Expand Down Expand Up @@ -60,4 +60,4 @@ macro_rules! make_test {
#[rustversion::stable]
make_test!();
#[rustversion::not(stable)]
make_test!(packable_is_structural);
make_test!();
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/pass/default_errors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::{error::UnknownTagError, Packable};

use core::{any::TypeId, convert::Infallible};

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
pub struct Point {
x: i32,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use packable::{Packable, PackableExt};
Expand Down
9 changes: 4 additions & 5 deletions packable/packable-derive-test/tests/pass/error_coercion.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use core::convert::Infallible;

use packable::{
error::UnpackErrorExt,
error::{UnknownTagError, UnpackError},
error::{UnknownTagError, UnpackError, UnpackErrorExt},
packer::Packer,
unpacker::Unpacker,
Packable,
};

use core::convert::Infallible;

pub struct Picky(u8);

#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/pass/mixed_enum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::{error::UnknownTagError, Packable};

use core::convert::Infallible;

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
#[packable(tag_type = u8)]
#[packable(unpack_error = UnknownTagError<u8>)]
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/pass/named_enum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::{error::UnknownTagError, Packable};

use core::convert::Infallible;

use packable::{error::UnknownTagError, Packable};

#[derive(Packable)]
#[packable(tag_type = u8)]
#[packable(unpack_error = UnknownTagError<u8>)]
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/pass/named_struct.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = Infallible)]
pub struct Point {
Expand Down
6 changes: 3 additions & 3 deletions packable/packable-derive-test/tests/pass/newtype.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2021-2022 IOTA Stiftung
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_imports)]

use packable::Packable;

use core::convert::Infallible;

use packable::Packable;

#[derive(Packable)]
#[packable(unpack_error = Infallible)]
pub struct Num(u32);
Expand Down
Loading

0 comments on commit cfea534

Please sign in to comment.