diff --git a/examples/rust/wasi-keyvalue-component-server/src/lib.rs b/examples/rust/wasi-keyvalue-component-server/src/lib.rs index 42e264c3..087af0ec 100644 --- a/examples/rust/wasi-keyvalue-component-server/src/lib.rs +++ b/examples/rust/wasi-keyvalue-component-server/src/lib.rs @@ -26,6 +26,7 @@ fn map_lock<'a, T, U>( f(lock).map_err(|err| store::Error::Other(err.to_string())) } +#[derive(Clone, Default)] pub struct Bucket(Arc>>>); impl Bucket { @@ -79,11 +80,10 @@ impl bindings::exports::wasi::keyvalue::store::Guest for Handler { type Bucket = Bucket; fn open(identifier: String) -> Result { - static STORE: OnceLock>>>>>> = - OnceLock::new(); - let store = STORE.get_or_init(|| Mutex::default()); + static STORE: OnceLock>> = OnceLock::new(); + let store = STORE.get_or_init(Mutex::default); let mut store = store.lock().expect("failed to lock store"); - let bucket = store.entry(identifier).or_default(); - Ok(store::Bucket::new(Bucket(Arc::clone(&bucket)))) + let bucket = store.entry(identifier).or_default().clone(); + Ok(store::Bucket::new(bucket)) } } diff --git a/examples/rust/wasi-keyvalue-nats-server/src/main.rs b/examples/rust/wasi-keyvalue-nats-server/src/main.rs index 750141e5..b7468781 100644 --- a/examples/rust/wasi-keyvalue-nats-server/src/main.rs +++ b/examples/rust/wasi-keyvalue-nats-server/src/main.rs @@ -121,14 +121,13 @@ async fn connect(url: Url) -> anyhow::Result { Ok(client) } +type Bucket = Arc>>; + #[derive(Clone, Debug, Default)] -pub struct Server(Arc>>>>>); +struct Server(Arc>>); impl Server { - async fn bucket( - &self, - bucket: impl AsRef<[u8]>, - ) -> Result>>> { + async fn bucket(&self, bucket: impl AsRef<[u8]>) -> Result { debug!("looking up bucket"); let store = self.0.read().await; store @@ -139,7 +138,7 @@ impl Server { } impl bindings::exports::wasi::keyvalue::store::HandlerBucket> for Server { - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn get( &self, _cx: Option, @@ -151,7 +150,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket> Ok(Ok(bucket.get(&key).cloned())) } - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn set( &self, _cx: Option, @@ -165,7 +164,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket> Ok(Ok(())) } - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn delete( &self, _cx: Option, @@ -178,7 +177,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket> Ok(Ok(())) } - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn exists( &self, _cx: Option, @@ -190,7 +189,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket> Ok(Ok(bucket.contains_key(&key))) } - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn list_keys( &self, _cx: Option, @@ -213,7 +212,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket> impl bindings::exports::wasi::keyvalue::store::Handler> for Server { // NOTE: Resource handle returned is just the `identifier` itself - #[instrument(level = "trace", ret)] + #[instrument(level = "trace", skip(_cx), ret)] async fn open( &self, _cx: Option,