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 mut article = Self::new(author.clone(), title.clone(), journal.clone(), date);
if let Some(volume) = map.get(K_VOLUME) {
article.volume = Some(volume.clone());
}
if let Some(number) = map.get(K_NUMBER) {
article.number = Some(number.clone());
}
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());
}
article.volume = map.get(K_VOLUME).cloned();
article.number = map.get(K_NUMBER).cloned();
article.number = map.get(K_NUMBER).cloned();
article.pages = map.get(K_PAGES).cloned();
article.url = map.get(K_URL).cloned();
Some(Box::new(article))
}

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

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

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

@ -48,14 +48,10 @@ impl FromHashMap for InCollection {
let date = parse_date(map.get(K_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 = Some(editor.clone());
}
if let Some(volume) = map.get(K_VOLUME) {
in_col.volume = Some(volume.clone());
}
in_col.editor = map.get(K_EDITOR).cloned();
in_col.volume = map.get(K_VOLUME).cloned();
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) {
in_col.position = Some(position.clone());

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

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

Loading…
Cancel
Save