From f7f497d380a2298e0ede8fd7247d6ad7e94fa9be Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Wed, 29 Mar 2023 08:29:11 +0900 Subject: [PATCH 1/2] First draft of public data structures --- Cargo.lock | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/lib.rs | 58 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 117 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6b817b..08d3641 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,3 +5,71 @@ version = 3 [[package]] name = "musichoard" version = "0.1.0" +dependencies = [ + "serde", + "uuid", +] + +[[package]] +name = "proc-macro2" +version = "1.0.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "uuid" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +dependencies = [ + "serde", +] diff --git a/Cargo.toml b/Cargo.toml index 4321e78..03065c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0", features = ["derive"] } +uuid = { version = "1.3", features = ["serde"] } diff --git a/src/lib.rs b/src/lib.rs index 7d12d9a..d7c1a7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,50 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +use serde::{Deserialize, Serialize}; +use uuid; + +/// The [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier). +type Mbid = uuid::Uuid; + +/// An artist. May be linked to MusicBrainz. +#[derive(Deserialize, Serialize)] +pub struct Artist { + pub name: String, + pub mbid: Option, } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +/// A single track on a release. +#[derive(Deserialize, Serialize)] +pub struct Track { + pub number: u32, + pub title: String, + pub artist: Artist, +} + +/// MusicHoard release corresponds to MusicBrainz' concept of a release. However, it does not link +/// to MusicBrainz as the intention of MusicHoard is to manage releases locally. +#[derive(Deserialize, Serialize)] +pub struct Release { + pub title: String, + pub artist: String, + pub tracks: Vec, +} + +/// MusicHoard uses MusicBrainz [primary release group +/// type](https://musicbrainz.org/doc/Release_Group/Type) +#[derive(Deserialize, Serialize)] +pub enum ReleaseGroupType { + Album, + Ep, + Single, + Other, +} + +/// MusicHoard uses MusicBrainz' [Release Group concept](https://musicbrainz.org/doc/Release_Group). +#[derive(Deserialize, Serialize)] +pub struct ReleaseGroup { + pub r#type: ReleaseGroupType, + pub title: String, + pub artist: Artist, + pub year: u32, + pub mbid: Option, + pub releases: Vec, } -- 2.45.2 From 057808c1cc7aa07aeb3c2d512991ad620f23b026 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Wed, 29 Mar 2023 09:44:59 +0900 Subject: [PATCH 2/2] Clean up documentation --- src/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d7c1a7d..2fa4bc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,35 +1,37 @@ +//! MusicHoard - a music collection manager. + use serde::{Deserialize, Serialize}; use uuid; -/// The [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier). -type Mbid = uuid::Uuid; +/// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID). +pub type Mbid = uuid::Uuid; -/// An artist. May be linked to MusicBrainz. +/// [Artist](https://musicbrainz.org/doc/Artist). #[derive(Deserialize, Serialize)] pub struct Artist { pub name: String, pub mbid: Option, } -/// A single track on a release. +/// [Track](https://musicbrainz.org/doc/Track). #[derive(Deserialize, Serialize)] pub struct Track { pub number: u32, pub title: String, pub artist: Artist, + pub mbid: Option, } -/// MusicHoard release corresponds to MusicBrainz' concept of a release. However, it does not link -/// to MusicBrainz as the intention of MusicHoard is to manage releases locally. +/// [Release](https://musicbrainz.org/doc/Release). #[derive(Deserialize, Serialize)] pub struct Release { pub title: String, pub artist: String, pub tracks: Vec, + pub mbid: Option, } -/// MusicHoard uses MusicBrainz [primary release group -/// type](https://musicbrainz.org/doc/Release_Group/Type) +/// [Release group primary type](https://musicbrainz.org/doc/Release_Group/Type). #[derive(Deserialize, Serialize)] pub enum ReleaseGroupType { Album, @@ -38,7 +40,7 @@ pub enum ReleaseGroupType { Other, } -/// MusicHoard uses MusicBrainz' [Release Group concept](https://musicbrainz.org/doc/Release_Group). +/// [Release group](https://musicbrainz.org/doc/Release_Group). #[derive(Deserialize, Serialize)] pub struct ReleaseGroup { pub r#type: ReleaseGroupType, -- 2.45.2