Add InCollection source

main
trivernis 4 years ago
parent 7b1bc9b3d3
commit 7cac672ef3

@ -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<Mutex<BibliographyDictionary>> {
Arc::clone(&self.entry_dictionary)
}
}
}

@ -25,4 +25,4 @@ impl Article {
pages: None,
}
}
}
}

@ -30,4 +30,4 @@ impl Book {
url: None,
}
}
}
}

@ -21,4 +21,4 @@ impl Booklet {
date: None,
}
}
}
}

@ -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,
}
}
}
}

@ -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<String>,
volume: Option<String>,
series: Option<String>,
chapter: Option<String>,
pages: Option<String>,
address: Option<String>,
edition: Option<String>,
}
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,
}
}
}

@ -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<Local>;
@ -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,
}
}

@ -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<String, BibliographyEntryReference>,
}
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 {
}
}
}

@ -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<Mutex<BibliographyEntry>>;
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()
}
}

@ -1,3 +1,3 @@
pub mod bibliography_entry;
pub mod bib_types;
pub mod bibliography_dict;
pub mod bib_types;
pub mod bibliography_entry;

@ -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)

@ -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<BibRef> {
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()
}
}
}

@ -12,7 +12,7 @@ pub struct BibRef {
/// and to access the corresponding bibliography entry.
#[derive(Clone, Debug)]
pub struct BibRefAnchor {
entry: Option<BibliographyEntryReference>
entry: Option<BibliographyEntryReference>,
}
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<Mutex<BibRefAnchor>> {
Arc::clone(&self.anchor)
}
}
}

@ -1,2 +1,2 @@
pub mod anchor;
pub mod bib_reference;
pub mod anchor;
Loading…
Cancel
Save