From 22ed20f30eb3f6b599b480512a28a0ceab68bfd4 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 3 Sep 2020 15:21:19 +0200 Subject: [PATCH] Add function to get ordered list of entries Signed-off-by: trivernis --- Cargo.toml | 2 +- src/bib_manager.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4e12693..af58af0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bibliographix" description = "A bibliography management crate." -version = "0.2.0" +version = "0.3.0" authors = ["trivernis "] edition = "2018" license = "Apache-2.0" diff --git a/src/bib_manager.rs b/src/bib_manager.rs index aa9c0ba..e7d4e6f 100644 --- a/src/bib_manager.rs +++ b/src/bib_manager.rs @@ -1,4 +1,5 @@ use crate::bibliography::bibliography_dict::BibliographyDictionary; +use crate::bibliography::bibliography_entry::BibliographyEntryReference; use crate::references::anchor::BibListAnchor; use std::sync::{Arc, Mutex}; @@ -52,4 +53,18 @@ impl BibManager { } }) } + + /// Returns the list of bibliography entries ordered by first referenced + pub fn get_entry_list_by_occurrence(&self) -> Vec { + let mut entries = Vec::new(); + let entry_dict = self.entry_dictionary.lock().unwrap(); + + for bib_ref in self.root_ref_anchor.lock().unwrap().references() { + if let Some(bib_entry) = entry_dict.get(bib_ref.key()) { + entries.push(bib_entry); + } + } + + entries + } }