rstmt_core/intervals/
mod.rs

1/*
2    Appellation: intervals <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5#[doc(inline)]
6pub use self::kinds::*;
7
8pub(crate) mod kinds;
9
10#[doc(hidden)]
11pub mod qualities;
12
13pub(crate) mod prelude {
14    pub use super::kinds::*;
15    pub use super::IntervalKind;
16}
17
18pub(crate) type IntervalTy = i8;
19
20pub trait MusicalInterval {
21    fn as_i8(&self) -> i8;
22}
23
24/// [IntoInterval] is a trait describing a method which consumes the current type,
25/// converting it into an [Intervals]
26pub trait IntoInterval {
27    fn into_interval(self) -> Intervals;
28}
29
30/// [IntervalKind] denotes objects used to explicitly define the various
31/// intervals in music theory.
32pub trait IntervalKind {
33    private!();
34    /// Returns the interval associated with the value
35    fn kind(&self) -> Intervals {
36        Intervals::from_value(self.value())
37    }
38    /// Returns the value associated with the interval
39    fn value(&self) -> IntervalTy;
40}
41
42/*
43 ************* Implementations *************
44*/
45
46impl<I> IntoInterval for I
47where
48    I: Into<Intervals>,
49{
50    fn into_interval(self) -> Intervals {
51        self.into()
52    }
53}
54
55impl IntervalKind for Intervals {
56    seal!();
57    fn value(&self) -> IntervalTy {
58        self.value()
59    }
60}