Skip to content

Commit 7526947

Browse files
committed
wrap Store in an Arc for cloning
Per spinframework/spin#1200, `Store` should not have implemented `Clone` in the first place, so we wrap it in an `Arc` to avoid cloning it. This also adds Clippy and Rustfmt checks to CI. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 910f515 commit 7526947

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ jobs:
6969
make install
7070
cd ../../..
7171
72+
- name: Lint
73+
shell: bash
74+
run: |
75+
cargo fmt --all -- --check
76+
cargo clippy --all-targets --all-features
77+
7278
- name: Build spin-python-engine
7379
shell: bash
7480
run: make

crates/spin-python-engine/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use {
1616
key_value, outbound_http,
1717
redis::{self, RedisParameter, RedisResult},
1818
},
19-
std::{env, ops::Deref, str},
19+
std::{env, ops::Deref, str, sync::Arc},
2020
};
2121

2222
thread_local! {
@@ -92,7 +92,7 @@ impl HttpResponse {
9292
#[pyo3::pyclass]
9393
#[pyo3(name = "Store")]
9494
struct Store {
95-
inner: key_value::Store,
95+
inner: Arc<key_value::Store>,
9696
}
9797

9898
#[pyo3::pymethods]
@@ -304,14 +304,14 @@ fn spin_redis_module(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
304304
#[pyo3::pyfunction]
305305
fn kv_open(name: String) -> Result<Store, Anyhow> {
306306
Ok(Store {
307-
inner: key_value::Store::open(name).map_err(Anyhow::from)?,
307+
inner: Arc::new(key_value::Store::open(name).map_err(Anyhow::from)?),
308308
})
309309
}
310310

311311
#[pyo3::pyfunction]
312312
fn kv_open_default() -> Result<Store, Anyhow> {
313313
Ok(Store {
314-
inner: key_value::Store::open_default().map_err(Anyhow::from)?,
314+
inner: Arc::new(key_value::Store::open_default().map_err(Anyhow::from)?),
315315
})
316316
}
317317

0 commit comments

Comments
 (0)