First draft of public data structures (#2)

Closes #1

Reviewed-on: https://git.wojciechkozlowski.eu/wojtek/musichoard/pulls/2
This commit is contained in:
Wojciech Kozlowski 2023-03-29 08:29:11 +09:00
parent d3ea77d62f
commit 4de22e5584
3 changed files with 119 additions and 11 deletions

68
Cargo.lock generated
View File

@ -5,3 +5,71 @@ version = 3
[[package]] [[package]]
name = "musichoard" name = "musichoard"
version = "0.1.0" 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",
]

View File

@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive"] }
uuid = { version = "1.3", features = ["serde"] }

View File

@ -1,14 +1,52 @@
pub fn add(left: usize, right: usize) -> usize { //! MusicHoard - a music collection manager.
left + right
use serde::{Deserialize, Serialize};
use uuid;
/// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID).
pub type Mbid = uuid::Uuid;
/// [Artist](https://musicbrainz.org/doc/Artist).
#[derive(Deserialize, Serialize)]
pub struct Artist {
pub name: String,
pub mbid: Option<Mbid>,
} }
#[cfg(test)] /// [Track](https://musicbrainz.org/doc/Track).
mod tests { #[derive(Deserialize, Serialize)]
use super::*; pub struct Track {
pub number: u32,
#[test] pub title: String,
fn it_works() { pub artist: Artist,
let result = add(2, 2); pub mbid: Option<Mbid>,
assert_eq!(result, 4); }
}
/// [Release](https://musicbrainz.org/doc/Release).
#[derive(Deserialize, Serialize)]
pub struct Release {
pub title: String,
pub artist: String,
pub tracks: Vec<Track>,
pub mbid: Option<Mbid>,
}
/// [Release group primary type](https://musicbrainz.org/doc/Release_Group/Type).
#[derive(Deserialize, Serialize)]
pub enum ReleaseGroupType {
Album,
Ep,
Single,
Other,
}
/// [Release group](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<Mbid>,
pub releases: Vec<Release>,
} }