FuelLabs/sway

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

Aberta

#3.925 aberto em 30 de jan. de 2023

 (1 comentário) (0 reação) (0 responsável)Rust (5.421 forks)batch import
P: lowgood first issue

Métricas do repositório

Stars
 (61.702 estrelas)
Métricas de merge de PR
 (Mesclagem média 22h 6m) (16 fundiu PRs em 30d)

Description

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.

Guia do colaborador