Skip to content

Commit

Permalink
chore: address clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Aug 2, 2024
1 parent eb150e0 commit 46fd649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions examples/rust/wasi-keyvalue-component-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<HashMap<String, Vec<u8>>>>);

impl Bucket {
Expand Down Expand Up @@ -79,11 +80,10 @@ impl bindings::exports::wasi::keyvalue::store::Guest for Handler {
type Bucket = Bucket;

fn open(identifier: String) -> Result<store::Bucket> {
static STORE: OnceLock<Mutex<HashMap<String, Arc<RwLock<HashMap<String, Vec<u8>>>>>>> =
OnceLock::new();
let store = STORE.get_or_init(|| Mutex::default());
static STORE: OnceLock<Mutex<HashMap<String, Bucket>>> = 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))
}
}
21 changes: 10 additions & 11 deletions examples/rust/wasi-keyvalue-nats-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ async fn connect(url: Url) -> anyhow::Result<async_nats::Client> {
Ok(client)
}

type Bucket = Arc<RwLock<HashMap<String, Bytes>>>;

#[derive(Clone, Debug, Default)]
pub struct Server(Arc<RwLock<HashMap<Bytes, Arc<RwLock<HashMap<String, Bytes>>>>>>);
struct Server(Arc<RwLock<HashMap<Bytes, Bucket>>>);

impl Server {
async fn bucket(
&self,
bucket: impl AsRef<[u8]>,
) -> Result<Arc<RwLock<HashMap<String, Bytes>>>> {
async fn bucket(&self, bucket: impl AsRef<[u8]>) -> Result<Bucket> {
debug!("looking up bucket");
let store = self.0.read().await;
store
Expand All @@ -139,7 +138,7 @@ impl Server {
}

impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>> for Server {
#[instrument(level = "trace", ret)]
#[instrument(level = "trace", skip(_cx), ret)]
async fn get(
&self,
_cx: Option<HeaderMap>,
Expand All @@ -151,7 +150,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>
Ok(Ok(bucket.get(&key).cloned()))
}

#[instrument(level = "trace", ret)]
#[instrument(level = "trace", skip(_cx), ret)]
async fn set(
&self,
_cx: Option<HeaderMap>,
Expand All @@ -165,7 +164,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>
Ok(Ok(()))
}

#[instrument(level = "trace", ret)]
#[instrument(level = "trace", skip(_cx), ret)]
async fn delete(
&self,
_cx: Option<HeaderMap>,
Expand All @@ -178,7 +177,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>
Ok(Ok(()))
}

#[instrument(level = "trace", ret)]
#[instrument(level = "trace", skip(_cx), ret)]
async fn exists(
&self,
_cx: Option<HeaderMap>,
Expand All @@ -190,7 +189,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>
Ok(Ok(bucket.contains_key(&key)))
}

#[instrument(level = "trace", ret)]
#[instrument(level = "trace", skip(_cx), ret)]
async fn list_keys(
&self,
_cx: Option<HeaderMap>,
Expand All @@ -213,7 +212,7 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>

impl bindings::exports::wasi::keyvalue::store::Handler<Option<HeaderMap>> 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<HeaderMap>,
Expand Down

0 comments on commit 46fd649

Please sign in to comment.