From dd4a39273735b720844700bee3828ebde52c2189 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 26 Jan 2023 18:35:35 +0100
Subject: [PATCH] WIP: We will load and write patch files for the database with
 auxiliary types.

---
 src/rust/amalib/src/db_cache.rs |  7 ++++---
 src/rust/amalib/src/db_kara.rs  | 35 ++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/rust/amalib/src/db_cache.rs b/src/rust/amalib/src/db_cache.rs
index 755235fa..e51ba7ed 100644
--- a/src/rust/amalib/src/db_cache.rs
+++ b/src/rust/amalib/src/db_cache.rs
@@ -9,17 +9,15 @@ use lru::LruCache;
 /// cache, if its the playlists that are updated, we clear only the playlist, if
 /// it's the database, we clear everything.
 #[allow(dead_code)]
-#[derive(Debug, Deserialize, Serialize)]
+#[derive(Debug)]
 pub struct AmaDB {
     /// Cache requests to lektord and patched karas. The first element is the
     /// lektord entry, the second one is the patched version.
     /// TODO: Find a structure that does COW to not duplicate too much
     ///       information in the patched version...
-    #[serde(skip, default = "new_empty_kara_lru")]
     karas: LruCache<i64, (KaraInfo, Option<KaraInfo>)>,
 
     /// The playlists. We don't save them...
-    #[serde(skip, default = "new_empty_playlist_lru")]
     playlists: LruCache<SmallString, Playlist>,
 
     /// The list of overrides, indexed by the local id of the kara.
@@ -56,6 +54,9 @@ fn new_empty_playlist_lru() -> LruCache<SmallString, Playlist> {
 }
 
 impl AmaDB {
+    /// Create a new empty [AmaDB].
+    pub fn new() -> Self {}
+
     /// Clear the database cache, and only the caches about karas.
     pub fn clear_database_cache(&mut self) {
         todo!()
diff --git a/src/rust/amalib/src/db_kara.rs b/src/rust/amalib/src/db_kara.rs
index bda0b88c..d635786b 100644
--- a/src/rust/amalib/src/db_kara.rs
+++ b/src/rust/amalib/src/db_kara.rs
@@ -4,7 +4,7 @@ use crate::*;
 
 /// Represent the possible types for a song. The custom field is here for
 /// flexibility, we box it so it's not too big and because it won't be common.
-#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
+#[derive(Debug, Clone, PartialEq, Eq)]
 pub enum SongType {
     OP,
     ED,
@@ -16,8 +16,7 @@ pub enum SongType {
 
 /// Represent the possible origins for a song. The custom field is here for
 /// flexibility, we box it so it's not too big and because it won't be common.
-#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
-#[serde(rename_all = "lowercase")]
+#[derive(Debug, Clone, PartialEq, Eq)]
 pub enum SongOrigin {
     Anime,
     VN,
@@ -28,7 +27,7 @@ pub enum SongOrigin {
 }
 
 /// Represent a global id for a kara, the pair (database, id).
-#[derive(Debug, Deserialize, Serialize, Getters, CopyGetters)]
+#[derive(Debug, Getters, CopyGetters)]
 pub struct KaraId {
     #[getset(get = "pub")]
     repo: SmallString,
@@ -108,7 +107,7 @@ impl<'a> TaggedObject<'a> for KaraInfo {
 }
 
 /// Represent what we want to override in a kara.
-#[derive(Debug, Clone, Deserialize, Serialize)]
+#[derive(Debug, Clone)]
 pub enum KaraInfoOverride {
     SongTitle(SmallString),
     SongSource(SmallString),
@@ -153,3 +152,29 @@ impl KaraInfo {
             != 0
     }
 }
+
+impl From<&str> for SongOrigin {
+    fn from(value: &str) -> Self {
+        match value {
+            "anime" => SongOrigin::Anime,
+            "music" => SongOrigin::Music,
+            "autre" => SongOrigin::Autre,
+            "game" => SongOrigin::Game,
+            "vb" => SongOrigin::VN,
+            custom => SongOrigin::Custom(Box::new(custom.into())),
+        }
+    }
+}
+
+impl From<&str> for SongType {
+    fn from(value: &str) -> Self {
+        match value {
+            "OP" => SongType::OP,
+            "ED" => SongType::ED,
+            "IS" => SongType::IS,
+            "MV" => SongType::MV,
+            "OT" => SongType::OT,
+            custom => SongType::Custom(Box::new(custom.into())),
+        }
+    }
+}
-- 
GitLab