Skip to content

Commit

Permalink
Update to rust 1.78
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr committed May 2, 2024
1 parent 1771bd8 commit fb9b699
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 51 deletions.
32 changes: 17 additions & 15 deletions src/data/music/intervals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Defines the musical intervals.

use std::fmt::{Display, Formatter, Result};

/// Defines the different musical intervals.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(missing_docs)]
Expand All @@ -19,22 +21,22 @@ pub enum Interval {
Octave,
}

impl ToString for Interval {
fn to_string(&self) -> String {
impl Display for Interval {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Interval::Unison => "Unison".to_string(),
Interval::MinorSecond => "Minor Second".to_string(),
Interval::MajorSecond => "Major Second".to_string(),
Interval::MinorThird => "Minor Third".to_string(),
Interval::MajorThird => "Major Third".to_string(),
Interval::PerfectFourth => "Perfect Fourth".to_string(),
Interval::Tritone => "Tritone".to_string(),
Interval::PerfectFifth => "Perfect Fifth".to_string(),
Interval::MinorSixth => "Minor Sixth".to_string(),
Interval::MajorSixth => "Major Sixth".to_string(),
Interval::MinorSeventh => "Minor Seventh".to_string(),
Interval::MajorSeventh => "Major Seventh".to_string(),
Interval::Octave => "Octave".to_string(),
Interval::Unison => write!(f, "Unison"),
Interval::MinorSecond => write!(f, "Minor Second"),
Interval::MajorSecond => write!(f, "Major Second"),
Interval::MinorThird => write!(f, "Minor Third"),
Interval::MajorThird => write!(f, "Major Third"),
Interval::PerfectFourth => write!(f, "Perfect Fourth"),
Interval::Tritone => write!(f, "Tritone"),
Interval::PerfectFifth => write!(f, "Perfect Fifth"),
Interval::MinorSixth => write!(f, "Minor Sixth"),
Interval::MajorSixth => write!(f, "Major Sixth"),
Interval::MinorSeventh => write!(f, "Minor Seventh"),
Interval::MajorSeventh => write!(f, "Major Seventh"),
Interval::Octave => write!(f, "Octave"),
}
}
}
44 changes: 22 additions & 22 deletions src/data/music/notes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Defines the notes and accidentals for use in generating music courses.

use std::fmt::{Display, Formatter};

/// Defines the names of the natural notes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(missing_docs)]
Expand All @@ -13,16 +15,16 @@ pub enum NaturalNote {
G,
}

impl ToString for NaturalNote {
fn to_string(&self) -> String {
match &self {
NaturalNote::A => "A".to_string(),
NaturalNote::B => "B".to_string(),
NaturalNote::C => "C".to_string(),
NaturalNote::D => "D".to_string(),
NaturalNote::E => "E".to_string(),
NaturalNote::F => "F".to_string(),
NaturalNote::G => "G".to_string(),
impl Display for NaturalNote {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
NaturalNote::A => write!(f, "A"),
NaturalNote::B => write!(f, "B"),
NaturalNote::C => write!(f, "C"),
NaturalNote::D => write!(f, "D"),
NaturalNote::E => write!(f, "E"),
NaturalNote::F => write!(f, "F"),
NaturalNote::G => write!(f, "G"),
}
}
}
Expand All @@ -36,12 +38,12 @@ pub enum Accidental {
Sharp,
}

impl ToString for Accidental {
fn to_string(&self) -> String {
match &self {
Accidental::Natural => String::new(),
Accidental::Flat => "♭".to_string(),
Accidental::Sharp => "♯".to_string(),
impl Display for Accidental {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Accidental::Natural => write!(f, ""),
Accidental::Flat => write!(f, "♭"),
Accidental::Sharp => write!(f, "♯"),
}
}
}
Expand Down Expand Up @@ -83,15 +85,13 @@ impl Note {
Accidental::Flat => "_flat".to_string(),
Accidental::Sharp => "_sharp".to_string(),
};
format!("{}{}", self.0.to_string(), accidental)
format!("{}{}", self.0, accidental)
}
}

impl ToString for Note {
fn to_string(&self) -> String {
let mut output = self.0.to_string();
output.push_str(&self.1.to_string());
output
impl Display for Note {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{}", self.0, self.1)
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/data/music/scales.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Defines musical scales for use in generating music courses.

use anyhow::{anyhow, Result};
use std::fmt::{Display, Formatter};

use crate::data::music::intervals::*;
use crate::data::music::notes::*;
Expand All @@ -25,13 +26,13 @@ pub enum ScaleType {
MinorPentatonic,
}

impl ToString for ScaleType {
fn to_string(&self) -> String {
impl Display for ScaleType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ScaleType::Major => "Major".to_string(),
ScaleType::Minor => "Minor".to_string(),
ScaleType::MajorPentatonic => "Major Pentatonic".to_string(),
ScaleType::MinorPentatonic => "Minor Pentatonic".to_string(),
ScaleType::Major => write!(f, "Major"),
ScaleType::Minor => write!(f, "Minor"),
ScaleType::MajorPentatonic => write!(f, "Major Pentatonic"),
ScaleType::MinorPentatonic => write!(f, "Minor Pentatonic"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

// Allow pedantic warnings but disable some that are not useful.
#![warn(clippy::pedantic)]
#![allow(clippy::doc_markdown)]
#![allow(clippy::float_cmp)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
Expand Down
15 changes: 7 additions & 8 deletions src/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use std::{
collections::BTreeMap,
fmt::{Display, Formatter},
fs::{self, File},
io::Write,
path::Path,
Expand Down Expand Up @@ -76,19 +77,17 @@ impl TestId {
}
}

impl ToString for TestId {
impl Display for TestId {
/// Converts the test ID to a valid string representation.
fn to_string(&self) -> String {
let mut s = self.0.to_string();
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)?;
if let Some(lesson_id) = &self.1 {
s.push_str("::");
s.push_str(&lesson_id.to_string());
write!(f, "::{lesson_id}")?;
}
if let Some(exercise_id) = &self.2 {
s.push_str("::");
s.push_str(&exercise_id.to_string());
write!(f, "::{exercise_id}")?;
}
s
Ok(())
}
}

Expand Down

0 comments on commit fb9b699

Please sign in to comment.