Switch to parking_lot::Mutex and reexport it

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 4 years ago
parent 741bdc6e12
commit 0138731ca7
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,7 +1,7 @@
[package]
name = "bibliographix"
description = "A bibliography management crate."
version = "0.5.0"
version = "0.6.0"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license = "Apache-2.0"
@ -14,3 +14,4 @@ repository = "https://github.com/Trivernis/bibliographix"
chrono = "0.4.15"
chrono-english = "0.1.4"
toml = "0.5.6"
parking_lot = "0.11.1"

@ -3,11 +3,12 @@ use crate::bibliography::bibliography_entry::{BibliographyEntry, BibliographyEnt
use crate::bibliography::keys::K_KEY;
use crate::bibliography::FromHashMap;
use crate::references::anchor::BibListAnchor;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::io;
use std::io::BufRead;
use std::iter::FromIterator;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use toml::Value;
/// The root manager for that should be used for further reference operations that
@ -34,7 +35,7 @@ impl BibManager {
/// Creates a new child BibManager with a child anchor and the parents entry dict
pub fn create_child(&self) -> BibManager {
let anchor = self.root_ref_anchor.lock().unwrap().create_anchor();
let anchor = self.root_ref_anchor.lock().create_anchor();
let entry_dict = Arc::clone(&self.entry_dictionary);
Self {
@ -50,13 +51,13 @@ impl BibManager {
/// Assigns the corresponding bib entry to each bib reference
pub fn assign_entries_to_references(&self) {
let entry_dict = self.entry_dictionary.lock().unwrap();
let mut root_anchor = self.root_ref_anchor.lock().unwrap();
let entry_dict = self.entry_dictionary.lock();
let mut root_anchor = self.root_ref_anchor.lock();
root_anchor.flatten();
let entries = root_anchor.references();
entries.iter().for_each(|e| {
if let Some(bib) = entry_dict.get(e.key()) {
e.anchor().lock().unwrap().entry = Some(bib)
e.anchor().lock().entry = Some(bib)
}
})
}
@ -65,9 +66,9 @@ impl BibManager {
pub fn get_entry_list_by_occurrence(&self) -> Vec<BibliographyEntryReference> {
let mut entries = Vec::new();
let mut inserted_keys = Vec::new();
let entry_dict = self.entry_dictionary.lock().unwrap();
let entry_dict = self.entry_dictionary.lock();
for bib_ref in self.root_ref_anchor.lock().unwrap().references() {
for bib_ref in self.root_ref_anchor.lock().references() {
if let Some(bib_entry) = entry_dict.get(bib_ref.key()) {
if !inserted_keys.contains(bib_ref.key()) {
entries.push(bib_entry);
@ -84,7 +85,7 @@ impl BibManager {
let mut contents = String::new();
reader.read_to_string(&mut contents)?;
let bib_content = contents.parse::<Value>()?;
let mut entry_dict = self.entry_dictionary.lock().unwrap();
let mut entry_dict = self.entry_dictionary.lock();
if let Some(table) = bib_content.as_table() {
let mut entries = table

@ -1,8 +1,9 @@
use crate::bibliography::bibliography_entry::{BibliographyEntry, BibliographyEntryReference};
use crate::bibliography::keys::K_KEY;
use crate::bibliography::FromHashMap;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
/// A dictionary that contains all bibliography entries
#[derive(Clone, Debug)]

@ -2,9 +2,10 @@ use crate::bibliography::bib_types::misc::Misc;
use crate::bibliography::bib_types::BibliographyType;
use crate::bibliography::keys::{K_KEY, K_NOTE};
use crate::bibliography::FromHashMap;
use parking_lot::Mutex;
use std::collections::hash_map::RandomState;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
/// A single bibliography entry
#[derive(Clone, Debug)]

@ -3,6 +3,8 @@ pub mod bibliography;
pub mod references;
pub mod utils;
pub use parking_lot::Mutex;
#[cfg(test)]
mod tests {
use crate::bib_manager::BibManager;
@ -15,17 +17,11 @@ mod tests {
fn it_inserts_and_flattens() {
let manager = BibManager::new();
let root_anchor = manager.root_ref_anchor();
let mut root_anchor = root_anchor.lock().unwrap();
let mut root_anchor = root_anchor.lock();
root_anchor.insert(BibRef::new("test".to_string()));
let child_anchor = root_anchor.create_anchor();
child_anchor
.lock()
.unwrap()
.insert(BibRef::new("test2".to_string()));
child_anchor
.lock()
.unwrap()
.insert(BibRef::new("test3".to_string()));
child_anchor.lock().insert(BibRef::new("test2".to_string()));
child_anchor.lock().insert(BibRef::new("test3".to_string()));
root_anchor.flatten();
assert_eq!(root_anchor.references().len(), 3)
@ -36,13 +32,13 @@ mod tests {
let manager = BibManager::new();
let ref1_1 = BibRef::new("ref1".to_string());
let anchor1 = ref1_1.anchor();
manager.root_ref_anchor().lock().unwrap().insert(ref1_1);
manager.root_ref_anchor().lock().insert(ref1_1);
let ref1_2 = BibRef::new("ref1".to_string());
let anchor2 = ref1_2.anchor();
manager.root_ref_anchor().lock().unwrap().insert(ref1_2);
manager.root_ref_anchor().lock().insert(ref1_2);
let ref3 = BibRef::new("ref2".to_string());
let anchor3 = ref3.anchor();
manager.root_ref_anchor().lock().unwrap().insert(ref3);
manager.root_ref_anchor().lock().insert(ref3);
let mut map: HashMap<String, String> = HashMap::new();
map.insert("key".to_string(), "ref1".to_string());
map.insert("type".to_string(), "article".to_string());
@ -50,17 +46,12 @@ mod tests {
map.insert("title".to_string(), "test_title".to_string());
map.insert("journal".to_string(), "test_journal".to_string());
map.insert("date".to_string(), "01.09.2020".to_string());
manager
.entry_dictionary()
.lock()
.unwrap()
.insert_map(&map)
.unwrap();
manager.entry_dictionary().lock().insert_map(&map).unwrap();
manager.assign_entries_to_references();
assert!(anchor1.lock().unwrap().entry.is_some());
assert!(anchor2.lock().unwrap().entry.is_some());
assert!(anchor3.lock().unwrap().entry.is_none());
assert!(anchor1.lock().entry.is_some());
assert!(anchor2.lock().entry.is_some());
assert!(anchor3.lock().entry.is_none());
}
#[test]

@ -1,5 +1,6 @@
use crate::references::bib_reference::BibRef;
use std::sync::{Arc, Mutex};
use parking_lot::Mutex;
use std::sync::Arc;
/// A bib list anchor that can be used to concurrently insert entries into a list
#[derive(Clone, Debug)]
@ -41,7 +42,7 @@ impl BibListAnchor {
let mut new_entries = Vec::with_capacity(self.entries.len());
self.entries.iter_mut().for_each(|e| match e {
BibListEntry::Anchor(a) => {
let mut anchor = a.lock().unwrap();
let mut anchor = a.lock();
anchor.flatten();
new_entries.append(&mut anchor.entries);
}

@ -1,5 +1,6 @@
use crate::bibliography::bibliography_entry::BibliographyEntryReference;
use std::sync::{Arc, Mutex};
use parking_lot::Mutex;
use std::sync::Arc;
/// A reference to a bibliography entry
#[derive(Clone, Debug)]

Loading…
Cancel
Save