Closed oovm closed 3 years ago
Thank you for the report, will investigate
This appears to be an issue with joinery
, rather than lazy_format
. Conveniently I am the author of both, so I'm going to transfer this issue to there.
Whoops, I see your point about format
working but lazy_format
failing. Transferring back!
I won't be able to test until later tonight, but upon re-read I think the issue is that, because each invocation of lazy_format!
creates an opaque, anonymous, unique type, so a.chain(kv)
can't succeed, because the two iterators (a
and kv
) have different element types. I'll try to figure out if there's a good way to account for this use case directly in lazy_format
; I ran into a similar issue with lazy_format!
being used in different branches of a match
, for which I added a special syntax directly to lazy_format
. In the meantime, the best solution is probably to use something like Either
to unify the types (which is probably what a lazy_format
solution would do anyway)
use either::Either;
// Don't need a lazy_format on `args` since we're just
// formatting each element directly
let a = self.args.iter().map(Either::Left);
let kv = self.kvs.iter().map(|(k, v)| lazy_format!("{} = {}", k, v)).map(Either::Right);
let joined = a.chain(kv).join_with(", ");
...
While the issue is connected to lazy_format returning unique types, any library solution would necessarily have to be in joinery
, since that's where support for joining heterogeneous sequences would need to be. I'm therefore closing this issue as outside of scope for lazy_format
.
Use simple format it works