I recently was required to add both a vec
of functions and a HashMap
of struct->function to an existing struct. The problem is, that struct has #[derive(Serialize, Deserialize, Debug, Clone)]
. That's all fine when the struct contained primitive data types, but one cannot (at least usefully) print a HashMap<Foo,FnOnce>
. It's also a problem for serialization, etc.
So, how can I flag these fields as ignored for these macros? Or, simply isolate them?
Here's a snip of the code in question:
type BlockchainResult = Result<(), Box<dyn Error>>;
type OnTransactionSettled<'lt> = Box<dyn FnOnce(&Transaction) -> BlockchainResult + 'lt>;
type OnBlockEvent<'lt> = Box<dyn FnOnce(&Block) -> BlockchainResult + 'lt>;
#[derive(Serialize, Deserialize, Debug)]
pub struct Blockchain <'lt> {
trans_observers: HashMap<&'lt Transaction, OnTransactionSettled<'lt>>,
block_observers: Vec<OnBlockEvent<'lt>>,
pub genesis_block: GenesisBlock,
pub blocks: Vec<Block>,
}
Sample error:
125 | #[derive(Serialize, Deserialize, Debug)]
| ----- in this derive macro expansion
...
130 | block_observers: Vec<OnBlockEvent<'lt>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn for<'r> FnOnce(&'r block::Block) -> Result<(), Box<(dyn StdError + 'static)>>` cannot be formatted using `{:?}` because it doesn't implement `Debug`