Change hashmap value mapping to use cloned

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 4 years ago
parent 4a66e92794
commit fea41f3810
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -43,18 +43,11 @@ impl FromHashMap for Article {
let date = parse_date(map.get(K_DATE)?)?; let date = parse_date(map.get(K_DATE)?)?;
let mut article = Self::new(author.clone(), title.clone(), journal.clone(), date); let mut article = Self::new(author.clone(), title.clone(), journal.clone(), date);
if let Some(volume) = map.get(K_VOLUME) { article.volume = map.get(K_VOLUME).cloned();
article.volume = Some(volume.clone()); article.number = map.get(K_NUMBER).cloned();
} article.number = map.get(K_NUMBER).cloned();
if let Some(number) = map.get(K_NUMBER) { article.pages = map.get(K_PAGES).cloned();
article.number = Some(number.clone()); article.url = map.get(K_URL).cloned();
}
if let Some(pages) = map.get(K_PAGES) {
article.pages = Some(pages.clone());
}
if let Some(url) = map.get(K_URL) {
article.url = Some(url.clone());
}
Some(Box::new(article)) Some(Box::new(article))
} }

@ -44,21 +44,11 @@ impl FromHashMap for Book {
let date = parse_date(map.get(K_DATE)?)?; let date = parse_date(map.get(K_DATE)?)?;
let mut book = Book::new(author.clone(), title.clone(), publisher.clone(), date); let mut book = Book::new(author.clone(), title.clone(), publisher.clone(), date);
if let Some(volume) = map.get(K_VOLUME) { book.volume = map.get(K_VOLUME).cloned();
book.volume = Some(volume.clone()); book.series = map.get(K_SERIES).cloned();
} book.address = map.get(K_ADDRESS).cloned();
if let Some(series) = map.get(K_SERIES) { book.edition = map.get(K_EDITION).cloned();
book.series = Some(series.clone()); book.url = map.get(K_URL).cloned();
}
if let Some(address) = map.get(K_ADDRESS) {
book.address = Some(address.clone());
}
if let Some(edition) = map.get(K_EDITION) {
book.edition = Some(edition.clone());
}
if let Some(url) = map.get(K_URL) {
book.url = Some(url.clone());
}
Some(Box::new(book)) Some(Box::new(book))
} }

@ -32,18 +32,10 @@ impl FromHashMap for Booklet {
let title = map.get(K_TITLE)?; let title = map.get(K_TITLE)?;
let mut booklet = Booklet::new(title.clone()); let mut booklet = Booklet::new(title.clone());
if let Some(author) = map.get(K_AUTHOR) { booklet.author = map.get(K_AUTHOR).cloned();
booklet.author = Some(author.clone()) booklet.how_published = map.get(K_HOW_PUBLISHED).cloned();
} booklet.address = map.get(K_ADDRESS).cloned();
if let Some(how_published) = map.get(K_HOW_PUBLISHED) { booklet.date = map.get(K_DATE).and_then(|d| parse_date(d));
booklet.how_published = Some(how_published.clone());
}
if let Some(address) = map.get(K_ADDRESS) {
booklet.address = Some(address.clone());
}
if let Some(date) = map.get(K_DATE) {
booklet.date = parse_date(date);
}
Some(Box::new(booklet)) Some(Box::new(booklet))
} }

@ -58,18 +58,10 @@ impl FromHashMap for InBook {
date, date,
); );
if let Some(volume) = map.get(K_VOLUME) { in_book.volume = map.get(K_VOLUME).cloned();
in_book.volume = Some(volume.clone()); in_book.series = map.get(K_SERIES).cloned();
} in_book.address = map.get(K_ADDRESS).cloned();
if let Some(series) = map.get(K_SERIES) { in_book.edition = map.get(K_EDITION).cloned();
in_book.series = Some(series.clone());
}
if let Some(address) = map.get(K_ADDRESS) {
in_book.address = Some(address.clone());
}
if let Some(edition) = map.get(K_EDITION) {
in_book.edition = Some(edition.clone())
}
Some(Box::new(in_book)) Some(Box::new(in_book))
} }

@ -48,14 +48,10 @@ impl FromHashMap for InCollection {
let date = parse_date(map.get(K_DATE)?)?; let date = parse_date(map.get(K_DATE)?)?;
let mut in_col = InCollection::new(author.clone(), title.clone(), publisher.clone(), date); let mut in_col = InCollection::new(author.clone(), title.clone(), publisher.clone(), date);
if let Some(editor) = map.get(K_EDITOR) { in_col.editor = map.get(K_EDITOR).cloned();
in_col.editor = Some(editor.clone()); in_col.volume = map.get(K_VOLUME).cloned();
}
if let Some(volume) = map.get(K_VOLUME) {
in_col.volume = Some(volume.clone());
}
if let Some(series) = map.get(K_SERIES) { if let Some(series) = map.get(K_SERIES) {
in_col.series = Some(series.clone()); Some(series.clone());
} }
if let Some(position) = map.get(K_POSITION) { if let Some(position) = map.get(K_POSITION) {
in_col.position = Some(position.clone()); in_col.position = Some(position.clone());

@ -34,21 +34,11 @@ impl FromHashMap for Manual {
let title = map.get(K_TITLE)?; let title = map.get(K_TITLE)?;
let mut manual = Manual::new(title.clone()); let mut manual = Manual::new(title.clone());
if let Some(author) = map.get(K_AUTHOR) { manual.author = map.get(K_AUTHOR).cloned();
manual.author = Some(author.clone()); manual.organization = map.get(K_ORGANIZATION).cloned();
} manual.address = map.get(K_ADDRESS).cloned();
if let Some(org) = map.get(K_ORGANIZATION) { manual.edition = map.get(K_EDITION).cloned();
manual.organization = Some(org.clone()); manual.date = map.get(K_DATE).and_then(|d| parse_date(d));
}
if let Some(address) = map.get(K_ADDRESS) {
manual.address = Some(address.clone());
}
if let Some(edition) = map.get(K_EDITION).and_then(|s| Some(s.clone())) {
Some(edition.clone());
}
if let Some(date) = map.get(K_DATE) {
manual.date = parse_date(date);
}
Some(Box::new(manual)) Some(Box::new(manual))
} }

@ -31,21 +31,11 @@ impl FromHashMap for Misc {
fn from_hash_map(map: &HashMap<String, String, RandomState>) -> Option<Box<Self>> { fn from_hash_map(map: &HashMap<String, String, RandomState>) -> Option<Box<Self>> {
let mut misc = Misc::new(); let mut misc = Misc::new();
if let Some(author) = map.get(K_AUTHOR) { misc.author = map.get(K_AUTHOR).cloned();
misc.author = Some(author.clone()) misc.title = map.get(K_TITLE).cloned();
} misc.url = map.get(K_URL).cloned();
if let Some(title) = map.get(K_TITLE) { misc.how_published = map.get(K_HOW_PUBLISHED).cloned();
misc.title = Some(title.clone()) misc.date = map.get(K_DATE).and_then(|d| parse_date(d));
}
if let Some(url) = map.get(K_URL) {
misc.url = Some(url.clone())
}
if let Some(how_pub) = map.get(K_HOW_PUBLISHED) {
misc.how_published = Some(how_pub.clone());
}
if let Some(date) = map.get(K_DATE) {
misc.date = parse_date(date);
}
Some(Box::new(misc)) Some(Box::new(misc))
} }

Loading…
Cancel
Save