Rust utilities for rewriting files
-
Rewriter: rewrites a file's contents -
Backup: restores a file's contents when dropped, unless explicitly disabled -
Span: names a region of a file, similar toproc-macro2::Span -
LineColumn: names a point in a file, similar toproc-macro2::LineColumn -
interface::Spanandinterface::LineColumn: traits that span and line-column types must implement to be used with this library
-
proc-macro2-span: By default,rewriteruses its ownSpanandLineColumntypes. When this feature is enabled,rewriterinstead uses the corresponding types fromproc-macro2. This feature impliesproc-macro2-implbelow. -
proc-macro2-impl: Implement theSpanandLineColumntraits for the corresponding types inproc-macro2.
The closest analogue to Rewriter of which we are aware is rust-analyzer's TextEdit.
The following are some notable differences:
-
Interface: One constructs a
Rewriterfrom a&str, performs a series ofrewrites, and then callscontentsto obtain the resulting text as aString. By comparison, one constructs aTextEditand thenapplys it to an&mut String. -
Referring to text:
Rewriterrefers to text usingSpans, which are composed of pairs ofLineColumns. EachLineColumncontains a line and a column. By comparison,TextEditrefers to text usingTextRanges, which are composed of pairs ofTextSizes. EachTextSizewraps au32byte offset. -
Stability:
Rewriteraims to provide a stable interface. By comparison, users of therust-analyzercrates are advised to pin versions or expect regular breaking changes.