magiclen / educe

This crate offers procedural macros designed to facilitate the swift implementation of Rust's built-in traits.
MIT License
127 stars 11 forks source link

bug(Debug): error[E0275]: overflow evaluating the requirement `engine::tests::borsh_diff::Sequence2TupleEntryChange<'_, &engine::tests::borsh_diff::BorshView, &engine::tests::borsh_diff::BorshView>: std::marker::Sized` #28

Open dzmitry-lahoda opened 3 months ago

dzmitry-lahoda commented 3 months ago

with 0.6 release got this:

    = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`engine`)
    = note: required for `Vec<Sequence2TupleEntryChange<'_, &BorshView, &BorshView>>` to implement `std::fmt::Debug`
    = note: the full type name has been written to '/home/dz/github.com/Layer-N/nord/target/debug/deps/engine-1c44dcde9cb6e8a5.long-type-14849732555947787797.txt'
    = note: 126 redundant requirements hidden
    = note: required for `&engine::tests::borsh_diff::BorshDiffs<'_>` to implement `std::fmt::Debug`
    = note: required for the cast from `&&engine::tests::borsh_diff::BorshDiffs<'_>` to `&dyn std::fmt::Debug`
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
dzmitry-lahoda commented 3 months ago
#[derive(Clone, PartialEq, Eq, educe::Educe)]
#[educe(Debug)]
#[repr(u8)]
pub enum BorshDiffs<'a> {
    /// if change will fail deserialization, for example fixed array changed to non fixed
    /// but tuple <-> struct is ok, and same type struct <-> tuple <-> fixed sequence is ok
    /// with type of change
    Serde(DiffPair<'a>) = 0,
    /// just checking value equality, like number value or string
    Eq(DiffPair<'a>) = 1,
    // /// exact same data in non singular container, so order change
    // /// with element positions change map
    // Order(#[educe(Debug(ignore))] DiffPair<'a>) = 2,
    // /// if to make set of elements in container, no equality
    // Set(#[educe(Debug(ignore))] DiffPair<'a>) = 3,
    /// any sort-oblivion sequence with 2-tuple like add(key)/remove(key)/modify(for value)  
    OrderedKeyValue(
        #[educe(Debug(ignore))] DiffPair<'a>,
        Vec<Sequence2TupleEntryChange<'a, &'a BorshView, &'a BorshView>>,
    ) = 4,
    // ... etc etc ...
    /// list of differences
    Multi(#[educe(Debug(ignore))] DiffPair<'a>, Vec<BorshDiffs<'a>>) = u8::MAX,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct DiffPair<'a> {
    #[allow(dead_code)]
    old: &'a BorshView,
    new: &'a BorshView,
}

#[derive(
    Clone, Debug, PartialEq, Eq, BorshSchema, BorshSerialize, BorshDeserialize, PartialOrd, Ord,
)]
pub struct BorshView {
    pub path: BorshPath,
    pub value: BorshViews,
}

#[derive(
    Clone, Debug, PartialEq, Eq, BorshSchema, BorshSerialize, BorshDeserialize, PartialOrd, Ord,
)]
#[borsh(use_discriminant = true)]
#[repr(u16)]
pub enum BorshViews {
    Empty = 0,
    Bool(bool),
    U8(u8),
    U16(u16),
    U32(u32),
    U64(u64),
    U128(u128),
    I8(i8),
    I16(i16),
    I32(i32),
    I64(i64),
    I128(i128),
    /// fixed length
    Tuple(Vec<BorshView>),
    /// non fixed length
    /// sequence of chars
    SequenceString(String),
    /// may have duplicate entries, can be Vec or Set, etc
    Sequence(Vec<BorshView>),
    /// fixed length
    FixedSequence(Vec<BorshView>),
    /// non fixed length
    /// may have duplicate keys
    /// really conventionally is just Sequence of Tuples
    Sequence2Tuple(Vec<(BorshView, BorshView)>),
    /// heterogenous fixed size sequence (unnamed struct), cannot be reordered
    /// specific case of map when key is unique and String
    /// fixed length
    NamedTuple(Vec<(String, BorshView)>),
    /// single element sequence (or single variant enum)
    /// fixed lenght
    Option(Box<BorshView>),
    /// single element heterogeneous map
    /// fixed length
    Enum(String, Box<BorshView>),
}

/// Somewhat valid Rust accessor to raw data similar to jq/xpath path like `.ob.markets["USD/BTC"].orderbook[0].price`
type BorshPath = String;

/// Old to new map updates difference structure.
/// Applicable to non fixed size containers only.
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Sequence2TupleEntryChange<'a, K, V> {
    Insert(K, V),
    Remove(K, V),
    Modify(K, V, V, BorshDiffs<'a>),
}
ijackson commented 1 month ago

This is #27

You can work around this by specifying bounds explictly, eg #[educe(Debug(bound()))] I think will work in this case.