Repository navigation
Changed
- Breaking: a new editing API that can no longer corrupt a document. Every operation that can fail returns
Result<_, EditError>, and a refused edit changes nothing.Editor::new(source, &parse_options, &edit_options)?replacesnew,with_parse_options,with_edit_optionsandwith_options.Editor::section(name)is a lookup that returnsOptionand never creates a section;section_or_insert(name)?creates one, andpreamble()edits the keys before the first header (0.4'ssection("")appended a[]section instead). Positions count body lines, so the header is never one:insert_entry,append_body_lines,insert_body_lines,remove_body_linesandbody_line_countreplaceinsert_entry_at_line,append_raw_lines,insert_raw_lines_at,remove_linesand the header-at-0 indexing, and out-of-range positions and reversed ranges are errors instead of being clamped. Handles borrow the editor exclusively, so a stale or removed handle no longer compiles;entry(key)andentry_at(index)replaceentries_mut(), andEntryEditor::index()and the newbody_line()are always current.remove_entryandrename_keyreturnResult<bool, EditError>, and a rename onto an existing key isErr(DuplicateKey).SeparatorSpacing::exact(before, after)?validates its whitespace, and theExactfields are the newWhitespacetype. Theeditormodule docs have a migration guide whose examples are compiled (#90) - Breaking: move to rowan 0.17.
SyntaxNode,SyntaxToken,SyntaxElement,Parse::green()andIniLang'srowan::Languageimpl now use rowan 0.17's types, so code that names rowan types needsrowan = "0.17". rowan 0.17 removes its mutable tree API (clone_for_update,detach,SyntaxNode::splice_children,new_root_mut, the*_by_kindhelpers), andSyntaxNode::green()returns&GreenNodeDatainstead of aCow: replacegreen().into_owned()withgreen().to_owned(), and edit throughEditoror by rebuilding green nodes withreplace_with(#99) - Diagnostics describe the INI text instead of internal token names, and each position gets at most one diagnostic.
=badreportsexpected a key before '='(wasunexpected token: LEX_ERROR),:xreportsexpected a key before ':',key junkreports onlyexpected '=' or ':'(orunexpected text after keywhenallow_no_valueis on), and a lone[reportsexpected section name and ']'instead of two diagnostics. Code that matches onParseError::messageor counts diagnostics will see the new text (#101)
Added
EditorisSend + Sync + UnwindSafe + RefUnwindSafe, andSectionEditorandEntryEditorareSend + Sync. The crate docs' new "Threads" section lists which types can cross threads; syntax nodes, tokens and theasttypes still cannot (#99, #102)ini_edit::MAX_INPUT_LEN, the largest document a tree can describe (u32::MAXbytes). The editor refuses documents and edits past its limit withEditError::DocumentTooLarge(#90, #93)
Fixed
- The editor no longer writes text that a reader would read back differently. Keys, values, section names, separator spacing and raw lines that would not round-trip are refused instead of written: for example, setting a value to
"a\n[evil]\nx=1"used to move every following entry into a new[evil]section, a key likea=bread back as the keya, and padded section names created a duplicate section every time the file was reopened. Values ending in a backslash, which absorbed the next line, are refused too (#90) - The editor's view always equals a reparse of its text. Raw lines containing line breaks, lines inserted above a header and removing a header used to leave the editor's tree disagreeing with the saved file, so later edits went to different lines depending on whether the file was reopened in between. Raw lines are now parsed, so a raw
k=2is an entry thatsetandrename_keyfind (#90) ParseError::displayputs the caret under the reported column. It was two columns to the left, three from line 1000 on, and further with tabs (#101)parseandparse_withpanic with a clear message on input longer thanMAX_INPUT_LENinstead of returning a tree whose length wrapped around (a 4 GiB document gave an empty tree with no diagnostics in release builds) (#93)- The published crate's own tests pass: 0.4.0's package left out the snapshot files, so 31 tests failed on its crates.io sources (#84)
Performance
Measured against 0.4.0 from crates.io on the same machine; parsing speed is unchanged.
- Editing is faster:
Editor::finishis about three times faster (gitea'sapp.example.ini: 364 to 115 µs), 200setcalls in one section of a 10,000-entry file are 29% faster and 200append_entrycalls 55% faster, because each edit rebuilds one immutable section instead of splicing a mutable tree line by line (#99) - The typed AST reads keys, values, names and comments directly from the tree's green nodes: walking every entry of an already-parsed
app.example.initakes 7 µs instead of 22, and finding one key 0.8 µs instead of 2.4 (#100)
Documentation
- Add SECURITY.md (private vulnerability reporting), CONTRIBUTING.md, and docs/standards.md, which records how ini-edit applies TigerStyle and SQLite's testing practices and the deliberate deviations (#86)