Expand description
Loaders for bib diff: read a file path, sniff format, return
format-neutral Entry records.
Lives next to crate::diff so the diff CLI / MCP tool can call a
single helper rather than re-implementing the BibTeX-or-JSON branch
at every call site. Content-sniffing is the source of truth: a
.bib file containing valid JSON is detected as JSON. Extension is
only consulted when content-sniffing is ambiguous (which it never
actually is — JSON either parses or it doesn’t), so extension is
effectively cosmetic in this helper. Kept here purely so callers
can also accept content via load_entries_from_str.
Enums§
- BibFormat
- Detected format of a bibliography file. Returned by
detect_format_from_strso callers can branch (e.g. log a warn when extension and content disagree).
Functions§
- detect_
format_ from_ str - Sniff format. Strategy: try parsing as JSON first (fast:
serde_jsonwill reject within bytes if the leading non-whitespace is@). If JSON parse fails, fall back to BibTeX. Note that an empty BibTeX file (zero entries) is legal, and an empty string parses as neither JSON nor BibTeX cleanly; we treat empty-or-whitespace-only as BibTeX so an empty.bibround-trips correctly. - load_
entries_ from_ path - Load a file and return its entries in the format-neutral shape. Errors are bubbled up verbatim with file-path context so the caller can present a useful error.
- load_
entries_ from_ str - Same as
load_entries_from_pathbut takes the bytes directly. The CLI uses this for the--question-idform (where the “before” side is a fresh DB snapshot, not a file).