Mercurial > lbo > hg > memoize
changeset 0:49c550904d88
Initial commit
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Wed, 14 Oct 2020 19:42:54 +0200 |
parents | |
children | df9526623f04 |
files | .hgignore Cargo.toml src/lib.rs |
diffstat | 3 files changed, 48 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Oct 14 19:42:54 2020 +0200 @@ -0,0 +1,2 @@ +^target/ +glob:Cargo.lock
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Cargo.toml Wed Oct 14 19:42:54 2020 +0200 @@ -0,0 +1,12 @@ +[package] +name = "memoize" +version = "0.1.0" +authors = ["Lewin Bormann <lewin@lewin-bormann.info>"] +edition = "2018" + +[lib] +proc-macro = true +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +lazy_static = "1.4"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib.rs Wed Oct 14 19:42:54 2020 +0200 @@ -0,0 +1,34 @@ +#![crate_type = "proc-macro"] + +use proc_macro::TokenStream; + +use lazy_static::lazy_static; + +use std::collections::HashMap; +use std::sync::Mutex; + +#[proc_macro_attribute] +pub fn memoize(attr: TokenStream, item: TokenStream) -> TokenStream { + let func = parse_macro_input + item +} + +lazy_static! { + static ref STORE: Mutex<HashMap<i32, bool>> = Mutex::new(HashMap::new()); +} + +// fn memoizer(a: i32) -> bool { +// let mut hm = &mut STORE.lock().unwrap(); +// if let Some(r) = hm.get(&a) { +// return *r; +// } +// let r = memoized_function(a); +// hm.insert(a, r); +// r +// } + +#[cfg(test)] +mod tests { + use super::*; + +}