Skip to main content

Module diff_input

Module diff_input 

Source
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_str so 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_json will 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 .bib round-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_path but takes the bytes directly. The CLI uses this for the --question-id form (where the “before” side is a fresh DB snapshot, not a file).