Skip to content

Commit 495cbb2

Browse files
committed
redb: add wasm32 support
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 499f523 commit 495cbb2

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

crates/nostr-redb/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![allow(clippy::mutable_key_type)]
1111

1212
use std::collections::HashSet;
13+
#[cfg(not(target_arch = "wasm32"))]
1314
use std::path::Path;
1415

1516
use nostr_database::prelude::*;
@@ -31,6 +32,7 @@ pub struct NostrRedb {
3132
impl NostrRedb {
3233
/// Persistent database
3334
#[inline]
35+
#[cfg(not(target_arch = "wasm32"))]
3436
pub fn persistent<P>(path: P) -> Result<Self, DatabaseError>
3537
where
3638
P: AsRef<Path>,
@@ -55,7 +57,8 @@ impl NostrRedb {
5557
}
5658
}
5759

58-
#[async_trait]
60+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
61+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
5962
impl NostrDatabase for NostrRedb {
6063
#[inline]
6164
fn backend(&self) -> Backend {
@@ -73,7 +76,8 @@ impl NostrDatabase for NostrRedb {
7376
}
7477
}
7578

76-
#[async_trait]
79+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
80+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
7781
impl NostrEventsDatabase for NostrRedb {
7882
#[inline]
7983
async fn save_event(&self, event: &Event) -> Result<SaveEventStatus, DatabaseError> {

crates/nostr-redb/src/store/core/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
// Distributed under the MIT software license
55

66
use std::collections::BTreeSet;
7+
#[cfg(not(target_arch = "wasm32"))]
8+
use std::fs;
9+
use std::iter;
710
use std::ops::Bound;
11+
#[cfg(not(target_arch = "wasm32"))]
812
use std::path::Path;
913
use std::sync::Arc;
10-
use std::{fs, iter};
1114

1215
use nostr::prelude::*;
1316
use nostr_database::flatbuffers::FlatBufferDecodeBorrowed;
@@ -58,6 +61,7 @@ impl Db {
5861
Ok(Self { env })
5962
}
6063

64+
#[cfg(not(target_arch = "wasm32"))]
6165
pub(crate) fn persistent<P>(path: P) -> Result<Self, Error>
6266
where
6367
P: AsRef<Path>,
@@ -72,6 +76,7 @@ impl Db {
7276
Self::new(env)
7377
}
7478

79+
// TODO: add support to in-memory with limited capacity?
7580
pub(crate) fn in_memory() -> Result<Self, Error> {
7681
let backend = InMemoryBackend::new();
7782
let env = Arc::new(Database::builder().create_with_backend(backend)?);

crates/nostr-redb/src/store/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Distributed under the MIT software license
55

66
use std::collections::BTreeSet;
7+
#[cfg(not(target_arch = "wasm32"))]
78
use std::path::Path;
89
use std::sync::Arc;
910

@@ -30,6 +31,7 @@ pub struct Store {
3031
}
3132

3233
impl Store {
34+
#[cfg(not(target_arch = "wasm32"))]
3335
pub fn persistent<P>(path: P) -> Result<Self, Error>
3436
where
3537
P: AsRef<Path>,

0 commit comments

Comments
 (0)