Skip to main content

Library

Struct Library 

Source
pub struct Library<'a> { /* private fields */ }
Expand description

A parsed BibTeX library.

Implementations§

Source§

impl<'a> Library<'a>

Source

pub fn new() -> Self

Create a new empty library

Source

pub fn parser() -> Parser

Create a parser with options

§Parallel Processing

The threads option only affects parse_files(). Single file parsing with parse() is sequential.

§Example
use bibtex_parser::Library;
// Parse multiple files in parallel
let library = Library::parser()
    .threads(4)
    .parse_files(&["file1.bib", "file2.bib"]).unwrap();

// Single-file parsing stays sequential
let content = "@article{demo, title=\"Demo\"}";
let library = Library::parser()
    .threads(4)
    .parse(content).unwrap();
Source

pub fn parse(input: &'a str) -> Result<Self>

Parse a BibTeX library from a string with default strict settings.

Source

pub fn parse_file(path: impl AsRef<Path>) -> Result<Library<'static>>

Parse a BibTeX library from a file into owned data.

Source

pub fn to_bibtex(&self) -> Result<String>

Serialize this library to BibTeX.

Source

pub fn write_file(&self, path: impl AsRef<Path>) -> Result<()>

Serialize this library to a BibTeX file.

Source

pub fn merge(&mut self, other: Self)

Merge another library into this one

Source

pub fn entries(&self) -> &[Entry<'a>]

Get all entries

Source

pub fn entries_mut(&mut self) -> &mut Vec<Entry<'a>>

Get mutable access to all entries

Source

pub fn strings(&self) -> &[StringDefinition<'a>]

Get all string definitions

Source

pub fn string(&self, name: &str) -> Option<&StringDefinition<'a>>

Get a string definition by name.

Source

pub fn string_value(&self, name: &str) -> Option<&Value<'a>>

Get a string definition value by name.

Source

pub fn preambles(&self) -> &[Preamble<'a>]

Get all preambles

Source

pub fn preambles_mut(&mut self) -> &mut Vec<Preamble<'a>>

Get mutable access to preambles

Source

pub fn comments(&self) -> &[Comment<'a>]

Get all comments

Source

pub fn comments_mut(&mut self) -> &mut Vec<Comment<'a>>

Get mutable access to comments

Source

pub fn failed_blocks(&self) -> &[FailedBlock<'a>]

Get malformed blocks retained by tolerant parsing.

Source

pub fn blocks(&self) -> Vec<Block<'_, 'a>>

Return blocks in source order.

Source

pub fn find_by_key(&self, key: &str) -> Option<&Entry<'a>>

Find entries by key

Source

pub fn find_by_key_ignore_case(&self, key: &str) -> Option<&Entry<'a>>

Find entries by key, ignoring ASCII case.

Source

pub fn contains_key(&self, key: &str) -> bool

Return true when the library contains key.

Source

pub fn find_by_type(&self, ty: &str) -> Vec<&Entry<'a>>

Find entries by type

Source

pub fn find_by_field(&self, field: &str, value: &str) -> Vec<&Entry<'a>>

Find entries by field value

Source

pub fn find_by_field_ignore_case( &self, field: &str, value: &str, ) -> Vec<&Entry<'a>>

Find entries by field value, ignoring ASCII case for the field name and value.

Source

pub fn find_by_doi(&self, doi: &str) -> Vec<&Entry<'a>>

Find entries whose normalized DOI matches doi.

Source

pub fn expand_value_ref(&self, value: &Value<'a>) -> Result<Value<'a>>

Alternative expansion that works with references (requires cloning for variables)

Source

pub fn get_expanded_string(&self, value: &Value<'a>) -> Result<String>

Get a fully expanded string value.

Source

pub fn into_owned(self) -> Library<'static>

Convert to owned version (no borrowed data)

Source

pub fn add_string(&mut self, name: &'a str, value: Value<'a>)

Add a string definition (useful for building libraries programmatically)

Source

pub fn add_entry(&mut self, entry: Entry<'a>)

Add an entry

Source

pub fn add_preamble(&mut self, value: Value<'a>)

Add a preamble

Source

pub fn add_comment(&mut self, comment: &'a str)

Add a comment

Source

pub fn resolve_strings(&mut self) -> Result<()>

Resolve string variables and concatenations in entries and preambles in place.

Source

pub fn normalize_doi_fields(&mut self)

Normalize DOI fields to lowercase 10.x/... form when recognizable.

Source

pub fn normalize_months(&mut self, style: MonthStyle)

Normalize month fields to a chosen representation.

Source

pub fn normalize_fields(&mut self, options: FieldNormalizeOptions)

Normalize field names and common BibLaTeX aliases.

Source

pub fn sort(&mut self, options: SortOptions)

Sort entries and/or fields in place.

Source

pub fn validate( &self, level: ValidationLevel, ) -> Vec<(usize, &Entry<'a>, Vec<ValidationError>)>

Validate all entries in the library Returns a list of entries with their indices and validation errors

Source

pub fn find_duplicate_keys(&self) -> Vec<&str>

Check for duplicate citation keys Returns a list of duplicate keys (each key appears once in the list even if it has multiple duplicates)

Source

pub fn find_duplicate_keys_ignore_case(&self) -> Vec<String>

Check for duplicate citation keys, ignoring ASCII case.

Source

pub fn find_duplicate_dois(&self) -> Vec<(String, Vec<&Entry<'a>>)>

Find duplicate DOI groups using normalized DOI values.

Source

pub fn validate_comprehensive( &self, level: ValidationLevel, ) -> ValidationReport<'_>

Validate all entries and return a comprehensive validation report

Source

pub fn stats(&self) -> LibraryStats

Get statistics about the library

Trait Implementations§

Source§

impl<'a> Clone for Library<'a>

Source§

fn clone(&self) -> Library<'a>

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<'a> Debug for Library<'a>

Source§

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

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

impl<'a> Default for Library<'a>

Source§

fn default() -> Library<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Library<'a>

§

impl<'a> RefUnwindSafe for Library<'a>

§

impl<'a> Send for Library<'a>

§

impl<'a> Sync for Library<'a>

§

impl<'a> Unpin for Library<'a>

§

impl<'a> UnsafeUnpin for Library<'a>

§

impl<'a> UnwindSafe for Library<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> Ungil for T
where T: Send,