typst / biblatex

A Rust crate for parsing and writing BibTeX and BibLaTeX files.
Apache License 2.0
120 stars 15 forks source link

parse_result first implementation #16

Closed ariroffe closed 2 years ago

ariroffe commented 2 years ago

Hi, in accordance with the issue I opened, I took the liberty of making this pull request. It adds a new method (in order to not break any existing code) to Bibliography, called parse_result, that returns a Result instead of an Option. The Err variant returns a string with the key of the entry that failed to parse. In the future, there could be a more complete explanation as to why parse failed / which fields were incorrect and why, but as a first approximation I think this works. I also added a couple of tests for it. Feel free to edit, of course (e.g. to modify the version of the package in Cargo.toml).

reknih commented 2 years ago

This now looks good to merge; I replaced the error strings with an enum so that library consumers distinguish between the errors more conveniently. The error messages are still available through the Display trait of the error enum.