FuelLabs/sway

refactor(fmt): use `drain_filter` during comment formatting when stabilized

開放

#3,925 建立於 2023年1月30日

 (1 則留言) (0 個反應) (0 位負責人)Rust (5,421 個分叉)batch import
P: lowgood first issue

倉庫指標

星標
 (61,702 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

BTreeMap does not have an equivalent for Range that also removes the yielded elements, however it does have a > drain_filter method.

A more efficient (performance and code-wise) alternative to this function using drain_filter might 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.

貢獻者指南