Skip to content

Commit

Permalink
Make Storage Send
Browse files Browse the repository at this point in the history
  • Loading branch information
cowlicks committed Jul 1, 2024
1 parent 61423de commit 44eb767
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ impl<T: RandomAccess + Debug> StorageTraits for T {}
/// Save data to a desired storage backend.
#[derive(Debug)]
pub struct Storage {
tree: Box<dyn StorageTraits>,
data: Box<dyn StorageTraits>,
bitfield: Box<dyn StorageTraits>,
oplog: Box<dyn StorageTraits>,
tree: Box<dyn StorageTraits + Send>,
data: Box<dyn StorageTraits + Send>,
bitfield: Box<dyn StorageTraits + Send>,
oplog: Box<dyn StorageTraits + Send>,
}

pub(crate) fn map_random_access_err(err: RandomAccessError) -> HypercoreError {
Expand Down Expand Up @@ -60,8 +60,9 @@ impl Storage {
Store,
) -> std::pin::Pin<
Box<
dyn std::future::Future<Output = Result<Box<dyn StorageTraits>, RandomAccessError>>
+ Send,
dyn std::future::Future<
Output = Result<Box<dyn StorageTraits + Send>, RandomAccessError>,
> + Send,
>,
>,
{
Expand Down Expand Up @@ -236,7 +237,7 @@ impl Storage {
Ok(())
}

fn get_random_access(&mut self, store: &Store) -> &mut Box<dyn StorageTraits> {
fn get_random_access(&mut self, store: &Store) -> &mut Box<dyn StorageTraits + Send> {
match store {
Store::Tree => &mut self.tree,
Store::Data => &mut self.data,
Expand All @@ -249,7 +250,8 @@ impl Storage {
#[instrument(err)]
pub async fn new_memory() -> Result<Self, HypercoreError> {
let create = |_| {
async { Ok(Box::new(RandomAccessMemory::default()) as Box<dyn StorageTraits>) }.boxed()
async { Ok(Box::new(RandomAccessMemory::default()) as Box<dyn StorageTraits + Send>) }
.boxed()
};
// No reason to overwrite, as this is a new memory segment
Self::open(create, false).await
Expand All @@ -270,7 +272,7 @@ impl Storage {
};
Ok(
Box::new(RandomAccessDisk::open(dir.as_path().join(name)).await?)
as Box<dyn StorageTraits>,
as Box<dyn StorageTraits + Send>,
)
}
.boxed()
Expand Down

0 comments on commit 44eb767

Please sign in to comment.