FuelLabs/sway
在 GitHub 查看refactor(fmt): use `drain_filter` during comment formatting when stabilized
Open
#3,925 创建于 2023年1月30日
P: lowgood first issue
仓库指标
- Star
- (61,702 star)
- PR 合并指标
- (平均合并 22小时 6分钟) (30 天内合并 16 个 PR)
描述
BTreeMapdoes not have an equivalent forRangethat also removes the yielded elements, however it does have a >drain_filtermethod.A more efficient (performance and code-wise) alternative to this function using
drain_filtermight look like:formatter.comment_map.drain_filter(|bs, _v| bs.start >= start && bs.end <= end)
Originally posted by @mitchmindtree in https://github.com/FuelLabs/sway/pull/3854#discussion_r1083691334
Currently, drain_filter is a a nightly-only API - I opted to use retain instead to filter out already formatted comments. We can perhaps consider doing this once drain_filter is stabilized.