macro_rules! MaybeStoredKey {
($key_name:ident, Value = $val:ty, Path = $path:expr, Serialize = $serialize:expr, Deserialize = $deserialize:expr) => { ... };
}Expand description
Example usage:
// need to import Signal, Global, SyncStorage from dioxus, more imports for the other stuff as well
use dioxus::prelude::*;
use tokio::{
fs::{File, remove_file},
io::{AsyncReadExt, AsyncWriteExt},
};
use std::{
ops::{Deref, DerefMut},
path::PathBuf,
};
struct ExampleKey;
MaybeStoredKey! {
ExampleKey,
Value = i32,
Path = "somedir",
Serialize = |val: &i32| val.to_string().into_bytes(),
Deserialize = |contents: &[u8]| {
String::from_utf8(contents.to_vec())
.unwrap()
.parse()
.unwrap()
}
}