Skip to content

Commit ca3d876

Browse files
committed
style: add #![deny(unsafe_code)] and isolate wit_bindgen in modules
Move wit_bindgen::generate! calls into separate `bindings` modules with #![allow(unsafe_code)] to isolate the unsafe code generation from the rest of the codebase. Add #![deny(unsafe_code)] at the crate level for all infrastructure components to enforce memory safety. This ensures that unsafe code is only used where explicitly needed (in the generated WIT bindings) while maintaining strict safety guarantees for all hand-written code.
1 parent cca1d21 commit ca3d876

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

components/infrastructure/kv-rocksdb/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
#![deny(unsafe_code)]
12
//! Placeholder RocksDB KV adapter implementing `kv` WIT interface.
23
//! To be completed with real RocksDB bindings suitable for WASM.
34
4-
wit_bindgen::generate!({
5-
world: "kv-adapter",
6-
path: "../../../wit",
7-
});
5+
mod bindings {
6+
#![allow(unsafe_code)]
7+
wit_bindgen::generate!({
8+
world: "kv-adapter",
9+
path: "../../../wit",
10+
});
11+
}
812

9-
use exports::keel::infrastructure::kv as wit_kv;
13+
use bindings::exports::keel::infrastructure::kv as wit_kv;
1014

1115
struct Adapter;
1216

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
#![deny(unsafe_code)]
12
//! # Cloudflare DO SQL Adapter
23
3-
wit_bindgen::generate!({
4-
world: "sql-adapter",
5-
path: "../../../wit",
6-
});
4+
mod bindings {
5+
#![allow(unsafe_code)]
6+
wit_bindgen::generate!({
7+
world: "sql-adapter",
8+
path: "../../../wit",
9+
});
10+
}

components/infrastructure/sql-spin-sqlite/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
#![deny(unsafe_code)]
12
//! Spin-backed SQLite implementation of the `sql` WIT interface.
23
//! Uses Spin's host-provided SQLite for performance and simplicity.
34
45
use spin_sdk::sqlite::{Connection, QueryResult as SpinQueryResult, Value as SpinValue};
56

6-
wit_bindgen::generate!({
7-
world: "sql-adapter",
8-
path: "../../../wit",
9-
});
7+
mod bindings {
8+
#![allow(unsafe_code)]
9+
wit_bindgen::generate!({
10+
world: "sql-adapter",
11+
path: "../../../wit",
12+
});
13+
}
1014

11-
use exports::keel::infrastructure::sql::{self as wit_sql};
15+
use bindings::exports::keel::infrastructure::sql::{self as wit_sql};
1216

1317
// Map WIT sql-value to Spin SQLite Value
1418
fn to_spin_value(v: &wit_sql::SqlValue) -> Result<SpinValue, wit_sql::SqlError> {
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
#![deny(unsafe_code)]
12
//! # sqllite Adapter
23
//!
34
//! ## Implementation Status
45
//!
56
6-
wit_bindgen::generate!({
7-
world: "sql-adapter",
8-
path: "../../../wit",
9-
});
7+
mod bindings {
8+
#![allow(unsafe_code)]
9+
wit_bindgen::generate!({
10+
world: "sql-adapter",
11+
path: "../../../wit",
12+
});
13+
}

0 commit comments

Comments
 (0)