Skip to content

Commit

Permalink
Let from_hypercore take SharedCore
Browse files Browse the repository at this point in the history
  • Loading branch information
cowlicks committed Sep 26, 2024
1 parent 18096bd commit 6bb418e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/hb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Debug, path::Path, sync::Arc};

use derive_builder::Builder;
use futures_lite::{AsyncRead, AsyncWrite, Stream};
use hypercore::{AppendOutcome, Hypercore};
use hypercore::{AppendOutcome, SharedCore};
use tokio::sync::RwLock;

use crate::{
Expand Down Expand Up @@ -33,8 +33,7 @@ impl Hyperbee {
stream: S,
is_initiator: bool,
) -> Result<(), HyperbeeError> {
self
.tree
self.tree
.read()
.await
.add_stream(stream, is_initiator)
Expand Down Expand Up @@ -158,7 +157,7 @@ impl Hyperbee {
}

/// Helper for creating a [`Hyperbee`] from a [`Hypercore`]
pub fn from_hypercore(hypercore: Hypercore) -> Result<Self, HyperbeeError> {
pub fn from_hypercore<T: Into<SharedCore>>(hypercore: T) -> Result<Self, HyperbeeError> {
Self::from_tree(Tree::from_hypercore(hypercore)?)
}

Expand Down
11 changes: 4 additions & 7 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use derive_builder::Builder;
use futures_lite::{AsyncRead, AsyncWrite, Stream, StreamExt};
use hypercore::{AppendOutcome, Hypercore, HypercoreBuilder, SharedCore, Storage};
use hypercore::{AppendOutcome, HypercoreBuilder, SharedCore, Storage};
use prost::Message;

use crate::{
Expand Down Expand Up @@ -34,8 +34,7 @@ impl Tree {
stream: S,
is_initiator: bool,
) -> Result<(), HyperbeeError> {
self
.blocks
self.blocks
.read()
.await
.add_stream(stream, is_initiator)
Expand Down Expand Up @@ -178,10 +177,8 @@ impl Tree {
Self::from_blocks(blocks)
}

pub fn from_hypercore(hypercore: Hypercore) -> Result<Self, HyperbeeError> {
let blocks = BlocksBuilder::default()
.core(SharedCore::from_hypercore(hypercore))
.build()?;
pub fn from_hypercore<T: Into<SharedCore>>(hypercore: T) -> Result<Self, HyperbeeError> {
let blocks = BlocksBuilder::default().core(hypercore.into()).build()?;
Self::from_blocks(blocks)
}

Expand Down

0 comments on commit 6bb418e

Please sign in to comment.