diff --git a/src/rust/amalib/src/db_cache.rs b/src/rust/amalib/src/db_cache.rs index e51ba7ed62fae79268f59e9a2e9642f19594769e..1ad263d46689bd2cb5fe4c9d72bcf744f50da5f9 100644 --- a/src/rust/amalib/src/db_cache.rs +++ b/src/rust/amalib/src/db_cache.rs @@ -9,15 +9,17 @@ 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)] +#[derive(Debug, Serialize, Deserialize)] 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. @@ -53,9 +55,22 @@ fn new_empty_playlist_lru() -> LruCache<SmallString, Playlist> { ) } +impl Default for AmaDB { + fn default() -> Self { + Self { + karas: new_empty_kara_lru(), + playlists: new_empty_playlist_lru(), + overrides: Default::default(), + local_ids: Default::default(), + } + } +} + impl AmaDB { /// Create a new empty [AmaDB]. - pub fn new() -> Self {} + pub fn new() -> Self { + Default::default() + } /// Clear the database cache, and only the caches about karas. pub fn clear_database_cache(&mut self) { diff --git a/src/rust/amalib/src/db_kara.rs b/src/rust/amalib/src/db_kara.rs index d635786bccca8673bbc0d20609fed255f72dbf6e..4aaffc1d215e512cc8803ca3e22d0ac4df7edb57 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)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum SongType { OP, ED, @@ -16,7 +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)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum SongOrigin { Anime, VN, @@ -27,7 +27,7 @@ pub enum SongOrigin { } /// Represent a global id for a kara, the pair (database, id). -#[derive(Debug, Getters, CopyGetters)] +#[derive(Debug, Getters, CopyGetters, Serialize, Deserialize)] pub struct KaraId { #[getset(get = "pub")] repo: SmallString, @@ -38,7 +38,7 @@ pub struct KaraId { /// A list of informations about a kara. This is the data from lektor. When /// queried we patch it with the overrides given by the user. -#[derive(Debug, Getters)] +#[derive(Debug, Getters, Serialize, Deserialize)] #[getset(get = "pub")] pub struct KaraInfo { song_title: SmallString, @@ -107,7 +107,7 @@ impl<'a> TaggedObject<'a> for KaraInfo { } /// Represent what we want to override in a kara. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum KaraInfoOverride { SongTitle(SmallString), SongSource(SmallString), diff --git a/src/rust/amalib/src/db_playlist.rs b/src/rust/amalib/src/db_playlist.rs index c50d6fccf1cbffb163244222be317447b42fef56..696f8c9f42d7b2857de2d40b3cea7822365fb211 100644 --- a/src/rust/amalib/src/db_playlist.rs +++ b/src/rust/amalib/src/db_playlist.rs @@ -2,7 +2,7 @@ use crate::*; -#[derive(Debug, Getters)] +#[derive(Debug, Getters, Serialize, Deserialize)] #[getset(get = "pub")] pub struct Playlist { name: SmallString, diff --git a/src/rust/amalib/src/db_tags.rs b/src/rust/amalib/src/db_tags.rs index c04e6d47b108a0787f576273e87704dc884869e3..a586f6147d22f54faeed803003650cf183498a50 100644 --- a/src/rust/amalib/src/db_tags.rs +++ b/src/rust/amalib/src/db_tags.rs @@ -164,7 +164,7 @@ impl<'a> TaggedObject<'a> for SimpleTagSystem { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] /// Represents a patch action to do on a tagged object. pub enum TagOverride<TK: AsRef<str> + Clone, TV: AsRef<str>> { /// Remove all tags.