singleton macro thing
This commit is contained in:
@@ -4,4 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
paste = "1.0.15"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
|||||||
@@ -1 +1,70 @@
|
|||||||
// TODO
|
#![allow(unused)]
|
||||||
|
|
||||||
|
use crate::types::{
|
||||||
|
CharacterDetail, CharacterFull, CharacterMini, CharacterSearch, Id, ItemMini, ItemSearch,
|
||||||
|
LightconeDetail, LightconeFull, LightconeMini, LightconeSearch, RelicMini, RelicSearch,
|
||||||
|
};
|
||||||
|
use paste::paste;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
macro_rules! define_data_store {
|
||||||
|
($base:ident, full) => {
|
||||||
|
paste::item! {
|
||||||
|
pub static [<$base:upper _DETAIL>]: OnceLock<[<$base Detail>]> = OnceLock::new();
|
||||||
|
pub static [<$base:upper _SEARCH>]: OnceLock<[<$base Search>]> = OnceLock::new();
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower _detail>]() -> &'static [<$base Detail>] {
|
||||||
|
[<$base:upper _DETAIL>]
|
||||||
|
.get()
|
||||||
|
.expect(concat!(stringify!([<$base:upper _DETAIL>]), " not initialized"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower _search>]() -> &'static [<$base Search>] {
|
||||||
|
[<$base:upper _SEARCH>]
|
||||||
|
.get()
|
||||||
|
.expect(concat!(stringify!([<$base:upper _SEARCH>]), " not initialized"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower full_by_id>](id: &Id) -> Option<&[<$base Full>]> {
|
||||||
|
[<get_ $base:lower _detail>]().0.get(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower _mini_by_id>](id: &Id) -> Option<&[<$base Mini>]> {
|
||||||
|
[<get_ $base:lower _search>]().0.get(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<set_ $base:lower _detail>](data: [<$base Detail>]) -> Result<(), [<$base Detail>]> {
|
||||||
|
[<$base:upper _DETAIL>].set(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<set_ $base:lower _search>](data: [<$base Search>]) -> Result<(), [<$base Search>]> {
|
||||||
|
[<$base:upper _SEARCH>].set(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
($base:ident, mini) => {
|
||||||
|
paste::item! {
|
||||||
|
pub static [<$base:upper _SEARCH>]: OnceLock<[<$base Search>]> = OnceLock::new();
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower _search>]() -> &'static [<$base Search>] {
|
||||||
|
[<$base:upper _SEARCH>]
|
||||||
|
.get()
|
||||||
|
.expect(concat!(stringify!([<$base:upper _SEARCH>]), " not initialized"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<get_ $base:lower _mini_by_id>](id: &Id) -> Option<&[<$base Mini>]> {
|
||||||
|
[<get_ $base:lower _search>]().0.get(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn [<set_ $base:lower _search>](data: [<$base Search>]) -> Result<(), [<$base Search>]> {
|
||||||
|
[<$base:upper _SEARCH>].set(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
define_data_store!(Character, full);
|
||||||
|
define_data_store!(Lightcone, full);
|
||||||
|
define_data_store!(Relic, mini);
|
||||||
|
define_data_store!(Item, mini);
|
||||||
|
|||||||
@@ -10,16 +10,7 @@ pub struct RelicMini {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub r#type: RelicType,
|
pub r#type: RelicType,
|
||||||
pub img_url: String,
|
pub img_url: String,
|
||||||
}
|
// lets just display these in the search page
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct RelicDetail(pub HashMap<Id, RelicFull>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct RelicFull {
|
|
||||||
pub name: String,
|
|
||||||
pub r#type: RelicType,
|
|
||||||
pub img_url: Uri,
|
|
||||||
pub two_pc: Desc,
|
pub two_pc: Desc,
|
||||||
pub four_pc: Option<Desc>,
|
pub four_pc: Option<Desc>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user