#[cfg(feature = "hashbrown")] use hashbrown::HashMap; #[cfg(hash_collections)] use core::{cmp::Eq, hash::Hash}; #[cfg(feature = "std")] use std::collections::HashMap; use alloc::{ collections::BTreeMap, string::String, }; use borsh::{BorshDeserialize, BorshSerialize}; #[derive(BorshSerialize, BorshDeserialize, Debug)] struct TupleA(W, u32); #[derive(BorshSerialize, BorshDeserialize, Debug)] struct NamedA { a: W, b: u32, } /// `T: PartialOrd` is injected here via field bound to avoid having this restriction on /// the struct itself #[cfg(hash_collections)] #[derive(BorshSerialize)] struct C1 { a: String, #[borsh(bound(serialize = "T: borsh::ser::BorshSerialize + Ord, U: borsh::ser::BorshSerialize"))] b: HashMap, } /// `T: PartialOrd + Hash + Eq` is injected here via field bound to avoid having this restriction on /// the struct itself #[allow(unused)] #[cfg(hash_collections)] #[derive(BorshDeserialize)] struct C2 { a: String, #[borsh(bound(deserialize = "T: Ord + Hash + Eq + borsh::de::BorshDeserialize, U: borsh::de::BorshDeserialize"))] b: HashMap, } /// `T: Ord` bound is required for `BorshDeserialize` derive to be successful #[derive(BorshSerialize, BorshDeserialize)] struct D { a: String, b: BTreeMap, } #[cfg(hash_collections)] #[derive(BorshSerialize)] struct G(#[borsh(skip)] HashMap, U); #[cfg(hash_collections)] #[derive(BorshDeserialize)] struct G1(#[borsh(skip)] HashMap, U); #[cfg(hash_collections)] #[derive(BorshDeserialize)] struct G2(HashMap, #[borsh(skip)] U); /// implicit derived `core::default::Default` bounds on `K` and `V` are dropped by empty bound /// specified, as `HashMap` hash its own `Default` implementation #[cfg(hash_collections)] #[derive(BorshDeserialize)] struct G3(#[borsh(skip, bound(deserialize = ""))] HashMap, U); #[cfg(hash_collections)] #[derive(BorshSerialize, BorshDeserialize)] struct H { x: BTreeMap, #[allow(unused)] #[borsh(skip)] y: U, } trait TraitName { type Associated; fn method(&self); } #[allow(unused)] #[derive(BorshSerialize)] struct ParametrizedWrongDerive where T: TraitName, { #[borsh(bound(serialize = "::Associated: borsh::ser::BorshSerialize"))] field: ::Associated, another: V, }