[][src]Crate hayagriva

Hayagriva provides a YAML-backed format and data model for various bibliography items as well as formatting for both in-text citations and reference lists based on these literature databases.

The crate is intended to assist scholarly writing and reference management and can be used both through a CLI and an API.

Below, there is an example of how to parse a YAML database and get a Modern Language Association-style citation.

Supported styles


use hayagriva::io::from_yaml_str;
use hayagriva::style::{Database, Mla};

let yaml = r#"
    type: Book
    title: Crazy Rich Asians
    author: Kwan, Kevin
    date: 2014
    publisher: Anchor Books
    location: New York, NY, US

// Parse a bibliography
let bib = from_yaml_str(yaml).unwrap();
assert_eq!(bib[0].date().unwrap().year, 2014);

// Format the reference
let db = Database::from_entries(bib.iter());
let mut mla = Mla::new();
let reference = db.bibliography(&mut mla, None);
assert_eq!(reference[0].display.value, "Kwan, Kevin. Crazy Rich Asians. Anchor Books, 2014.");

Formatting for in-text citations is available through implementors of the style::CitationStyle trait whereas bibliographies can be created by style::BibliographyStyle. Both traits are used through a style::Database which provides methods to format its records as bibliographies and citations using references to implementors to these traits.

If the default features are enabled, Hayagriva supports BibTeX and BibLaTeX bibliographies. You can use io::from_biblatex_str to parse such bibliographies.

Should you need more manual control, the library's native Entry struct also offers an implementation of the From<&biblatex::Entry>-Trait. You will need to depend on the biblatex crate to obtain its Entry. Therefore, you could also use your BibLaTeX content like this:

use hayagriva::Entry;
let converted: Entry = your_biblatex_entry.into();

If you do not need BibLaTeX compatibility, you can use Hayagriva without the default features by writing this in your Cargo.toml:

hayagriva = { version = "0.1", default-features = false }


Hayagriva uses a custom selector language that enables you to filter bibliographies by type of media. For more information about selectors, refer to the selectors.md file. While you can parse user-defined selectors using the function Selector::parse, you may instead want to use the selector macro to avoid the run time cost of parsing a selector when working with constant selectors.

use hayagriva::select;
use hayagriva::io::from_yaml_str;

let yaml = r#"
    type: Article
    author: Gross, E. P.
    title: Structure of a Quantized Vortex in Boson Systems
    date: 1961-05
    page-range: 454-477
    doi: 10.1007/BF02731494
        issue: 3
        volume: 20
        title: Il Nuovo Cimento

let entries = from_yaml_str(yaml).unwrap();
let journal = select!((Article["date"]) > ("journal":Periodical));

There are two ways to check if a selector matches an entry. You should use Selector::matches if you just want to know if an item matches a selector and Selector::apply to continue to work with the data from parents of a matching entry. Keep in mind that the latter function will return Some even if no sub-entry was bound / if the hash map is empty.



Reading and writing YAML bibliographies.


Language-dependant string transformations.


Citation and bibliography styles.


Base types for the bibliography items and their content.



Construct a Selector.



A citable item in a bibliography.


The error when a value is invalid for a field.



A selector used to filter bibliographies and match on entries.


The error when parsing a selector expression fails.


The data types that can possibly be held by the various fields of an Entry.