diff --git a/src/bib_manager.rs b/src/bib_manager.rs index bb0a8c7..6bd91f5 100644 --- a/src/bib_manager.rs +++ b/src/bib_manager.rs @@ -1,6 +1,6 @@ -use std::sync::{Arc, Mutex}; -use crate::references::anchor::BibListAnchor; use crate::bibliography::bibliography_dict::BibliographyDictionary; +use crate::references::anchor::BibListAnchor; +use std::sync::{Arc, Mutex}; /// The root manager for that should be used for further reference operations that /// go beyond insertion. @@ -28,4 +28,4 @@ impl BibManager { pub fn entry_dictionary(&self) -> Arc> { Arc::clone(&self.entry_dictionary) } -} \ No newline at end of file +} diff --git a/src/bibliography/bib_types/article.rs b/src/bibliography/bib_types/article.rs index 6b4ca4c..346cee9 100644 --- a/src/bibliography/bib_types/article.rs +++ b/src/bibliography/bib_types/article.rs @@ -25,4 +25,4 @@ impl Article { pages: None, } } -} \ No newline at end of file +} diff --git a/src/bibliography/bib_types/book.rs b/src/bibliography/bib_types/book.rs index cf78ee2..5a7c1d8 100644 --- a/src/bibliography/bib_types/book.rs +++ b/src/bibliography/bib_types/book.rs @@ -30,4 +30,4 @@ impl Book { url: None, } } -} \ No newline at end of file +} diff --git a/src/bibliography/bib_types/booklet.rs b/src/bibliography/bib_types/booklet.rs index 528fb61..17034ef 100644 --- a/src/bibliography/bib_types/booklet.rs +++ b/src/bibliography/bib_types/booklet.rs @@ -21,4 +21,4 @@ impl Booklet { date: None, } } -} \ No newline at end of file +} diff --git a/src/bibliography/bib_types/in_book.rs b/src/bibliography/bib_types/in_book.rs index 33ce486..f04ec5b 100644 --- a/src/bibliography/bib_types/in_book.rs +++ b/src/bibliography/bib_types/in_book.rs @@ -16,7 +16,13 @@ pub struct InBook { impl InBook { /// Creates a new InBook source with only the mandatory values filled - pub fn new(author: String, title: String, position: String, publisher: String, date:LocalDate) -> Self { + pub fn new( + author: String, + title: String, + position: String, + publisher: String, + date: LocalDate, + ) -> Self { Self { author, title, @@ -29,4 +35,4 @@ impl InBook { edition: None, } } -} \ No newline at end of file +} diff --git a/src/bibliography/bib_types/in_collection.rs b/src/bibliography/bib_types/in_collection.rs new file mode 100644 index 0000000..a5d85ac --- /dev/null +++ b/src/bibliography/bib_types/in_collection.rs @@ -0,0 +1,36 @@ +use crate::bibliography::bib_types::LocalDate; + +/// A source that is in a collection +#[derive(Clone, Debug)] +pub struct InCollection { + author: String, + title: String, + publisher: String, + date: LocalDate, + editor: Option, + volume: Option, + series: Option, + chapter: Option, + pages: Option, + address: Option, + edition: Option, +} + +impl InCollection { + /// Creates a new InCollection source with only the mandatory fields filled + pub fn new(author: String, title: String, publisher: String, date: LocalDate) -> Self { + Self { + author, + title, + publisher, + date, + editor: None, + volume: None, + series: None, + chapter: None, + pages: None, + address: None, + edition: None, + } + } +} diff --git a/src/bibliography/bib_types/mod.rs b/src/bibliography/bib_types/mod.rs index 73a1a42..c2b2b51 100644 --- a/src/bibliography/bib_types/mod.rs +++ b/src/bibliography/bib_types/mod.rs @@ -1,13 +1,15 @@ use crate::bibliography::bib_types::article::Article; use crate::bibliography::bib_types::book::Book; -use chrono::{Date, Local}; use crate::bibliography::bib_types::booklet::Booklet; use crate::bibliography::bib_types::in_book::InBook; +use crate::bibliography::bib_types::in_collection::InCollection; +use chrono::{Date, Local}; pub mod article; pub mod book; pub mod booklet; pub mod in_book; +pub mod in_collection; pub type LocalDate = Date; @@ -18,7 +20,7 @@ pub enum BibliographyType { Book(Book), Booklet(Booklet), InBook(InBook), - InCollection, + InCollection(InCollection), Manual, Thesis, TechReport, @@ -26,4 +28,4 @@ pub enum BibliographyType { Misc, Url, Repository, -} \ No newline at end of file +} diff --git a/src/bibliography/bibliography_dict.rs b/src/bibliography/bibliography_dict.rs index dca3361..17c3020 100644 --- a/src/bibliography/bibliography_dict.rs +++ b/src/bibliography/bibliography_dict.rs @@ -1,6 +1,6 @@ +use crate::bibliography::bibliography_entry::{BibliographyEntry, BibliographyEntryReference}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; -use crate::bibliography::bibliography_entry::{BibliographyEntryReference, BibliographyEntry}; /// A dictionary that contains all bibliography entries #[derive(Clone, Debug)] @@ -8,7 +8,6 @@ pub struct BibliographyDictionary { entries: HashMap, } - impl BibliographyDictionary { /// Creates a new empty BibliographyDictionary pub fn new() -> Self { @@ -19,7 +18,8 @@ impl BibliographyDictionary { /// Inserts a bibliography entry into the map pub fn insert(&mut self, entry: BibliographyEntry) { - self.entries.insert(entry.key(), Arc::new(Mutex::new(entry))); + self.entries + .insert(entry.key(), Arc::new(Mutex::new(entry))); } /// Returns the reference to the bibliography entry with the given key @@ -31,5 +31,3 @@ impl BibliographyDictionary { } } } - - diff --git a/src/bibliography/bibliography_entry.rs b/src/bibliography/bibliography_entry.rs index a52263f..ffe6f46 100644 --- a/src/bibliography/bibliography_entry.rs +++ b/src/bibliography/bibliography_entry.rs @@ -1,5 +1,5 @@ -use std::sync::{Arc, Mutex}; use crate::bibliography::bib_types::BibliographyType; +use std::sync::{Arc, Mutex}; /// A single bibliography entry #[derive(Clone, Debug)] @@ -11,7 +11,6 @@ pub struct BibliographyEntry { pub type BibliographyEntryReference = Arc>; - impl BibliographyEntry { /// Creates a new bibliography entry with the given key pub fn new(key: String) -> Self { @@ -27,4 +26,3 @@ impl BibliographyEntry { self.key.clone() } } - diff --git a/src/bibliography/mod.rs b/src/bibliography/mod.rs index bcb8a62..e8b0d5a 100644 --- a/src/bibliography/mod.rs +++ b/src/bibliography/mod.rs @@ -1,3 +1,3 @@ -pub mod bibliography_entry; +pub mod bib_types; pub mod bibliography_dict; -pub mod bib_types; \ No newline at end of file +pub mod bibliography_entry; diff --git a/src/lib.rs b/src/lib.rs index 5700712..f410465 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ -pub mod references; -pub mod bibliography; pub mod bib_manager; +pub mod bibliography; +pub mod references; #[cfg(test)] mod tests { - use crate::references::bib_reference::BibRef; use crate::bib_manager::BibManager; + use crate::references::bib_reference::BibRef; #[test] fn it_inserts_and_flattens() { @@ -14,8 +14,14 @@ mod tests { let mut root_anchor = root_anchor.lock().unwrap(); 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() + .unwrap() + .insert(BibRef::new("test2".to_string())); + child_anchor + .lock() + .unwrap() + .insert(BibRef::new("test3".to_string())); root_anchor.flatten(); assert_eq!(root_anchor.references().len(), 3) diff --git a/src/references/anchor.rs b/src/references/anchor.rs index adca40b..c0746fc 100644 --- a/src/references/anchor.rs +++ b/src/references/anchor.rs @@ -39,15 +39,13 @@ impl BibListAnchor { /// anchor in the vector pub fn flatten(&mut self) { 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(); - anchor.flatten(); - new_entries.append(&mut anchor.entries); - } - BibListEntry::Ref(bib_ref) => new_entries.push(BibListEntry::Ref(bib_ref.clone())) + self.entries.iter_mut().for_each(|e| match e { + BibListEntry::Anchor(a) => { + let mut anchor = a.lock().unwrap(); + anchor.flatten(); + new_entries.append(&mut anchor.entries); } + BibListEntry::Ref(bib_ref) => new_entries.push(BibListEntry::Ref(bib_ref.clone())), }); self.entries = new_entries; @@ -55,10 +53,15 @@ impl BibListAnchor { /// Returns all references that are contained in the entry list pub fn references(&self) -> Vec { - self.entries.iter().filter_map(|e| if let BibListEntry::Ref(r) = e { - Some(r.clone()) - } else { - None - }).collect() + self.entries + .iter() + .filter_map(|e| { + if let BibListEntry::Ref(r) = e { + Some(r.clone()) + } else { + None + } + }) + .collect() } -} \ No newline at end of file +} diff --git a/src/references/bib_reference.rs b/src/references/bib_reference.rs index a07d57c..f029250 100644 --- a/src/references/bib_reference.rs +++ b/src/references/bib_reference.rs @@ -12,7 +12,7 @@ pub struct BibRef { /// and to access the corresponding bibliography entry. #[derive(Clone, Debug)] pub struct BibRefAnchor { - entry: Option + entry: Option, } impl BibRef { @@ -20,7 +20,7 @@ impl BibRef { pub fn new(key: String) -> Self { Self { key, - anchor: Arc::new(Mutex::new(BibRefAnchor {entry: None})) + anchor: Arc::new(Mutex::new(BibRefAnchor { entry: None })), } } @@ -28,4 +28,4 @@ impl BibRef { pub fn anchor(&self) -> Arc> { Arc::clone(&self.anchor) } -} \ No newline at end of file +} diff --git a/src/references/mod.rs b/src/references/mod.rs index 3c12e15..9efe2b3 100644 --- a/src/references/mod.rs +++ b/src/references/mod.rs @@ -1,2 +1,2 @@ +pub mod anchor; pub mod bib_reference; -pub mod anchor; \ No newline at end of file