Is there an idiomatic way to count the elements in an iterator before the application of a filter?

35 points IvanMalison

I want to count the elements in an iterator before the application of a filter without making an intermediate collection.

I was able to write a macro that sort of allows you to do this (see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=193a0514414cce7cdb727259f7bcecf3)
but I'm wondering if there is a more idomatic way to do this.