Heya! So I have a static hashmap for storing what characters have which beepboops. It only took this freaking mess:
use core::cell::LazyCell;
use core::ops::Deref;
use agb::hash_map::HashMap;
use alloc::vec::Vec;
static MorseBindings: SuperLazyCell<HashMap<char, Vec<MorseSegment>>> = SuperLazyCell::new(|| {
let dot = MorseSegment::Dot;
let dash = MorseSegment::Dash;
let fin = MorseSegment::LetterEnd;
let mut map = HashMap::new();
map.insert('a', alloc::vec![dot, dash, fin]);
[other characters inserted here]
map
});
//This super-cursed abomination of sins is just so the compiler will stop yelling about LazyCell not being threadsafe... on the single threaded GBA. Yip-E. I really wish core had LazyLock >.<
struct SuperLazyCell<T, F = fn() -> T>(LazyCell<T, F>);
unsafe impl<T, F: FnOnce() -> T> Sync for SuperLazyCell<T, F> {}
impl<T, F: FnOnce() -> T> SuperLazyCell<T, F> {
pub const fn new(f: F) -> SuperLazyCell<T, F> {
SuperLazyCell(LazyCell::new(f))
}
}
impl<T, F: FnOnce() -> T> Deref for SuperLazyCell<T, F> {
type Target = T;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
I did not do this by myself. My wife had to carefully walk me through the whole process, which took hours. For a hashmap. Thank you, Rust, and also what the actual #$@&*@#($$@#($%&@#.
My wife just said "Baby's first deref impl!" and I'm so sorry I know exactly what that is now. (I mean, I was going to have to learn what it is eventually so I'm glad I had a hand to hold.)
"Baby's first unsafe trait, too!"
This isn't what I thought I was going to be writing a log about, lol. I did a lot of design today on a fast typing layout for the GBA which I think is really cool- you can access every character in the english alphabet and all the numbers and a bunch of punctuation in less than 5 key presses each, and I made it so more frequently picked characters are closer to the center. Here, I'll just post a picture.