Open dzmitry-lahoda opened 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>),
}
This is #27
You can work around this by specifying bounds explictly, eg #[educe(Debug(bound()))]
I think will work in this case.
with 0.6 release got this: