diff --git a/database/src/medium.rs b/database/src/medium.rs index 0c31a1b..f1ec431 100644 --- a/database/src/medium.rs +++ b/database/src/medium.rs @@ -267,10 +267,8 @@ impl Database { for part_index in work_parts { if !part_index.is_empty() { - let index = str::parse(part_index).or(Err(Error::ParsingError( - "part index", - String::from(part_index), - )))?; + let index = str::parse(part_index) + .map_err(|_| Error::ParsingError("part index", String::from(part_index)))?; part_indices.push(index); } diff --git a/database/src/recordings.rs b/database/src/recordings.rs index 82e5804..b78ffc6 100644 --- a/database/src/recordings.rs +++ b/database/src/recordings.rs @@ -49,11 +49,11 @@ impl Performance { /// Get a string representation of the performance. // TODO: Replace with impl Display. pub fn get_title(&self) -> String { - let mut text = String::from(if self.is_person() { + let mut text = if self.is_person() { self.unwrap_person().name_fl() } else { self.unwrap_ensemble().name - }); + }; if self.has_role() { text = text + " (" + &self.unwrap_role().name + ")"; @@ -249,7 +249,7 @@ impl Database { let recording_description = Recording { id: row.id, work, - comment: row.comment.clone(), + comment: row.comment, performances: performance_descriptions, }; diff --git a/database/src/works.rs b/database/src/works.rs index 6b62d9f..bc03c13 100644 --- a/database/src/works.rs +++ b/database/src/works.rs @@ -130,51 +130,49 @@ impl Database { .values(row) .execute(&self.connection)?; - match work { - Work { - instruments, - parts, - sections, - .. - } => { - for instrument in instruments { - let row = InstrumentationRow { - id: rand::random(), - work: work_id.to_string(), - instrument: instrument.id, - }; + let Work { + instruments, + parts, + sections, + .. + } = work; - diesel::insert_into(instrumentations::table) - .values(row) - .execute(&self.connection)?; - } + for instrument in instruments { + let row = InstrumentationRow { + id: rand::random(), + work: work_id.to_string(), + instrument: instrument.id, + }; - for (index, part) in parts.into_iter().enumerate() { - let row = WorkPartRow { - id: rand::random(), - work: work_id.to_string(), - part_index: index as i64, - title: part.title, - }; + diesel::insert_into(instrumentations::table) + .values(row) + .execute(&self.connection)?; + } - diesel::insert_into(work_parts::table) - .values(row) - .execute(&self.connection)?; - } + for (index, part) in parts.into_iter().enumerate() { + let row = WorkPartRow { + id: rand::random(), + work: work_id.to_string(), + part_index: index as i64, + title: part.title, + }; - for section in sections { - let row = WorkSectionRow { - id: rand::random(), - work: work_id.to_string(), - title: section.title, - before_index: section.before_index as i64, - }; + diesel::insert_into(work_parts::table) + .values(row) + .execute(&self.connection)?; + } - diesel::insert_into(work_sections::table) - .values(row) - .execute(&self.connection)?; - } - } + for section in sections { + let row = WorkSectionRow { + id: rand::random(), + work: work_id.to_string(), + title: section.title, + before_index: section.before_index as i64, + }; + + diesel::insert_into(work_sections::table) + .values(row) + .execute(&self.connection)?; } Ok(())