GameLispGameLisp 是一个用于 Rust 游戏开发的脚本语言。了解详情请看:https://gamelisp.rs/Shredder 项目Shredder 项目主要针对于 Rust 的智能指针的“垃圾回收”,更多细节请看博客原文:https://blog.typingtheory.com/shredder-garbage-collection-as-a-library-for-rust/derive_aktorderive_aktor 是一个宏库,使用起来还是挺方便的,项目地址:https://github.com/insanitybit/derive_aktorpub struct KeyValueStore<U>where U: Hash + Eq + Send + 'static{inner_store: HashMap<U, String>,self_actor: Option<KeyValueStoreActor<U>>,}impl<U: Hash + Eq + Send + 'static> KeyValueStore<U> {pub fn new() -> Self {Self {inner_store: HashMap::new(),self_actor: None,}}}// All methods in this block form our Actor's API#[derive_actor]impl<U: Hash + Eq + Send + 'static> KeyValueStore<U> {pub fn query(&self, key: U, f: Box<dyn Fn(Option<String>) + Send + 'static>) {println!("query");f(self.inner_store.get(&key).map(String::from))}pub fn set(&mut self, key: U, value: String) {println!("set");self.inner_store.insert(key, value);}}#[tokio::main]async fn main() {let (kv_store, handle) = KeyValueStoreActor::new(KeyValueStore::new()).await;// We can use an async API that's typed and nominalkv_store.query("foo", Box::new(|value| println!("before {:?}", value))).await;kv_store.set("foo", "bar".to_owned()).await;kv_store.query("foo", Box::new(|value| println!("after {:?}", value))).await;// We must drop any references to kv_store before we await the handle, or it will leak!drop(kv_store);handle.await;}
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。