Skip to main content

BibEntry

Struct BibEntry 

Source
pub struct BibEntry {
    pub entry_type: String,
    pub key: String,
    pub key_span: Range<usize>,
    pub fields: BTreeMap<String, String>,
}
Expand description

A single parsed BibTeX entry: one @type{...} record.

The entry type and field names are normalized to lowercase, because BibTeX treats them case-insensitively; the citation key is preserved verbatim, because keys are case-sensitive. Fields live in a BTreeMap, so fields iterates in sorted, stable order. Values are stored as raw text exactly as written, outer {} or "" delimiters included; bare values have none. A field name repeated within one entry keeps its last value. No TeX decoding or name parsing.

§Examples

use mos_bib::parse_bibtex;

let bib = parse_bibtex("@article{knuth1984, title = {Literate Programming}}")?;
let entry = &bib.entries["knuth1984"];
assert_eq!(entry.entry_type, "article");
assert_eq!(entry.key, "knuth1984");
assert_eq!(entry.fields["title"], "{Literate Programming}");

Fields§

§entry_type: String

The entry type without the leading @, lowercased (e.g. article).

§key: String

The citation key, preserved verbatim (e.g. knuth1984).

§key_span: Range<usize>

Byte range of key inside the parsed BibTeX source.

§fields: BTreeMap<String, String>

Field name (lowercased) to raw value text including its outer delimiters, in sorted name order.

Implementations§

Source§

impl BibEntry

Source

pub fn field_text(&self, name: &str) -> Option<&str>

A field’s value with its outer {} / "" delimiters removed; see unwrap_value. Inner text is still raw (no TeX decoding).

§Examples
use mos_bib::parse_bibtex;

let bib = parse_bibtex(r#"@book{k, title = {The {TeX}book}, year = "1984"}"#)?;
let entry = &bib.entries["k"];
assert_eq!(entry.field_text("title"), Some("The {TeX}book"));
assert_eq!(entry.field_text("year"), Some("1984"));
assert_eq!(entry.field_text("pages"), None);

Trait Implementations§

Source§

impl Clone for BibEntry

Source§

fn clone(&self) -> BibEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BibEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BibEntry

Source§

impl PartialEq for BibEntry

Source§

fn eq(&self, other: &BibEntry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BibEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.