maidsafe / sn_dbc

Safe Network DBCs
BSD 3-Clause "New" or "Revised" License
15 stars 16 forks source link

require IntoIterator<Item = (DbcContentHash, DbcTransaction)> for SpendBook trait #65

Closed dan-da closed 3 years ago

dan-da commented 3 years ago

another attempt to require IntoIterator for SpendBook trait, to make usage more idiomatic and eliminate Box.

I figured out i could constrain the IntoIterator supertrait by specifying Item=<(x,y)>. So that works well.

We'd also like to be able to iterate over a spendbook reference. To that end, I impl'd IntoIterator for &SimpleSpendBook. That works fine.

However, I wasn't able to require IntoIterator supertrait where Item=<(&x, &y)>. When I try this I get into lifetime hell and compiler seems to want lifetimes on all parent structs, eg KeyManager, Mint, etc which I wasn't willing to do, and also I'm nearing limits of my Rust understanding. So hopefully there is a simple solution I am missing...?

For now I left it that the SpendBook trait itself only requires IntoIterator(x,y). SimpleSpendBook also impls IntoIterator(&x, &y), which is what mint-repl example uses to avoid a spendbook.clone() in for loop.

I think this PR should not be merged until the above is resolved satisfactorily. Because it should not be necessary to consume/clone spendbook to iterate over it, so we should require that trait implementers also impl the by-ref version, as SimpleSpendBook does.

suggestions?