Skip to content

Commit 5801280

Browse files
committed
Enforce compile error on non-portable DbConnection methods
1 parent 7574854 commit 5801280

2 files changed

Lines changed: 14 additions & 74 deletions

File tree

crates/codegen/src/rust.rs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,19 +1485,9 @@ impl DbConnection {{
14851485
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
14861486
/// Most applications should call [`Self::run_threaded`] to spawn a thread
14871487
/// which advances the connection automatically.
1488-
///
1489-
/// # Panics
1490-
/// At runtime if called on any `wasm32` target.
1488+
#[cfg(not(target_arch = \"wasm32\"))]
14911489
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {{
1492-
#[cfg(target_arch = \"wasm32\")]
1493-
{{
1494-
panic!(\"`DbConnection::advance_one_message_blocking` is not supported on WebAssembly (wasm32); \\
1495-
prefer using `advance_one_message` or `advance_one_message_async` instead\");
1496-
}}
1497-
#[cfg(not(target_arch = \"wasm32\"))]
1498-
{{
1499-
self.imp.advance_one_message_blocking()
1500-
}}
1490+
self.imp.advance_one_message_blocking()
15011491
}}
15021492
15031493
/// Process one WebSocket message, `await`ing until one is received.
@@ -1521,35 +1511,15 @@ impl DbConnection {{
15211511
}}
15221512
15231513
/// Spawn a thread which processes WebSocket messages as they are received.
1524-
///
1525-
/// # Panics
1526-
/// At runtime if called on any `wasm32` target.
1514+
#[cfg(not(target_arch = \"wasm32\"))]
15271515
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {{
1528-
#[cfg(target_arch = \"wasm32\")]
1529-
{{
1530-
panic!(\"`DbConnection::run_threaded` is not supported on WebAssembly (wasm32); \\
1531-
prefer using `DbConnection::run_background` instead\");
1532-
}}
1533-
#[cfg(not(target_arch = \"wasm32\"))]
1534-
{{
1535-
self.imp.run_threaded()
1536-
}}
1516+
self.imp.run_threaded()
15371517
}}
15381518
1539-
/// Spawn a task which processes WebSocket messages as they are received.
1540-
///
1541-
/// # Panics
1542-
/// At runtime if called on any non-`wasm32` target.
1519+
/// Spawn a background task which processes WebSocket messages as they are received.
1520+
#[cfg(target_arch = \"wasm32\")]
15431521
pub fn run_background(&self) {{
1544-
#[cfg(not(target_arch = \"wasm32\"))]
1545-
{{
1546-
panic!(\"`DbConnection::run_background` is only supported on WebAssembly (wasm32); \\
1547-
prefer using `DbConnection::run_threaded` instead\");
1548-
}}
1549-
#[cfg(target_arch = \"wasm32\")]
1550-
{{
1551-
self.imp.run_background()
1552-
}}
1522+
self.imp.run_background()
15531523
}}
15541524
15551525
/// Run an `async` loop which processes WebSocket messages when polled.

crates/codegen/tests/snapshots/codegen__codegen_rust.snap

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,19 +1916,9 @@ impl DbConnection {
19161916
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
19171917
/// Most applications should call [`Self::run_threaded`] to spawn a thread
19181918
/// which advances the connection automatically.
1919-
///
1920-
/// # Panics
1921-
/// At runtime if called on any `wasm32` target.
1919+
#[cfg(not(target_arch = "wasm32"))]
19221920
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {
1923-
#[cfg(target_arch = "wasm32")]
1924-
{
1925-
panic!("`DbConnection::advance_one_message_blocking` is not supported on WebAssembly (wasm32); \
1926-
prefer using `advance_one_message` or `advance_one_message_async` instead");
1927-
}
1928-
#[cfg(not(target_arch = "wasm32"))]
1929-
{
1930-
self.imp.advance_one_message_blocking()
1931-
}
1921+
self.imp.advance_one_message_blocking()
19321922
}
19331923

19341924
/// Process one WebSocket message, `await`ing until one is received.
@@ -1952,35 +1942,15 @@ impl DbConnection {
19521942
}
19531943

19541944
/// Spawn a thread which processes WebSocket messages as they are received.
1955-
///
1956-
/// # Panics
1957-
/// At runtime if called on any `wasm32` target.
1945+
#[cfg(not(target_arch = "wasm32"))]
19581946
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {
1959-
#[cfg(target_arch = "wasm32")]
1960-
{
1961-
panic!("`DbConnection::run_threaded` is not supported on WebAssembly (wasm32); \
1962-
prefer using `DbConnection::run_background` instead");
1963-
}
1964-
#[cfg(not(target_arch = "wasm32"))]
1965-
{
1966-
self.imp.run_threaded()
1967-
}
1947+
self.imp.run_threaded()
19681948
}
19691949

1970-
/// Spawn a task which processes WebSocket messages as they are received.
1971-
///
1972-
/// # Panics
1973-
/// At runtime if called on any non-`wasm32` target.
1950+
/// Spawn a background task which processes WebSocket messages as they are received.
1951+
#[cfg(target_arch = "wasm32")]
19741952
pub fn run_background(&self) {
1975-
#[cfg(not(target_arch = "wasm32"))]
1976-
{
1977-
panic!("`DbConnection::run_background` is only supported on WebAssembly (wasm32); \
1978-
prefer using `DbConnection::run_threaded` instead");
1979-
}
1980-
#[cfg(target_arch = "wasm32")]
1981-
{
1982-
self.imp.run_background()
1983-
}
1953+
self.imp.run_background()
19841954
}
19851955

19861956
/// Run an `async` loop which processes WebSocket messages when polled.

0 commit comments

Comments
 (0)