eryon_nrt/traits/
convert.rs

1/*
2    Appellation: convert <module>
3    Contrib: @FL03
4*/
5use crate::types::{Note, Octave};
6
7pub trait AsNote {
8    fn as_note(&self) -> Note;
9}
10
11pub trait IntoNote {
12    fn into_note(self) -> Note;
13}
14
15/// A trait for converting a reference into an octave
16pub trait AsOctave {
17    fn as_octave(&self) -> Octave;
18}
19
20/// A trait for converting a type into an octave
21pub trait IntoOctave {
22    fn into_octave(self) -> Octave;
23}
24
25/*
26 ************* Implementations *************
27*/
28impl<T> IntoOctave for T
29where
30    T: Into<Octave>,
31{
32    fn into_octave(self) -> Octave {
33        self.into()
34    }
35}
36
37impl<T> IntoNote for T
38where
39    T: Into<Note>,
40{
41    fn into_note(self) -> Note {
42        self.into()
43    }
44}
45
46impl<T> AsOctave for T
47where
48    T: Clone + IntoOctave,
49{
50    fn as_octave(&self) -> Octave {
51        self.clone().into_octave()
52    }
53}