Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"core/amt-ipld",
"core/block-format",
"core/cid-ext",
"core/datastore",
"core/ds/rocksdb",
"core/fs-lock",
Expand Down
11 changes: 11 additions & 0 deletions core/cid-ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "cid-ext"
version = "0.1.0"
authors = ["PolkaX <https://github.com/PolkaX>"]
edition = "2018"

[dependencies]
cid = { version = "0.4", features = ["impl-serde"] }

[features]
nightly = []
22 changes: 22 additions & 0 deletions core/cid-ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![cfg_attr(feature = "nightly", feature(specialization))]

use cid::Cid;

/// A trait that represents whether a CID exists.
pub trait HasCid {
/// Whether a CID exists.
fn has_cid(&self) -> Option<&Cid>;
}

#[cfg(feature = "nightly")]
impl<T> HasCid for T {
default fn has_cid(&self) -> Option<&Cid> {
None
}
}

impl<T: AsRef<Cid>> HasCid for T {
fn has_cid(&self) -> Option<&Cid> {
Some(self.as_ref())
}
}
2 changes: 2 additions & 0 deletions core/hamt-ipld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ thiserror = "1.0"

block-format = { package = "rust-block-format", path = "../block-format" }
ipld-cbor = { package = "rust-ipld-cbor", path = "../ipld/cbor", features = ["bigint"] }
cid-ext = { path = "../cid-ext" }

[dev-dependencies]
matches = "0.1"
Expand All @@ -30,3 +31,4 @@ serde_json = "1.0"

[features]
test-hash = []
nightly = [ "cid-ext/nightly" ]
19 changes: 1 addition & 18 deletions core/hamt-ipld/src/ipld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use block_format::Block as BlockT;
use cid::{Cid, Codec};
use cid_ext::HasCid;
use serde::{de::DeserializeOwned, Serialize};

use crate::error::*;
Expand All @@ -16,24 +17,6 @@ pub trait CborIpldStore {
fn put<T: Serialize + HasCid>(&mut self, v: T) -> Result<Cid>;
}

/// A trait that represents whether a CID exists.
pub trait HasCid {
/// Whether a CID exists.
fn has_cid(&self) -> Option<&Cid>;
}

impl<T> HasCid for T {
default fn has_cid(&self) -> Option<&Cid> {
None
}
}

impl<T: AsRef<Cid>> HasCid for T {
fn has_cid(&self) -> Option<&Cid> {
Some(self.as_ref())
}
}

#[derive(Debug)]
#[cfg_attr(test, derive(Clone))]
pub struct BasicCborIpldStore<B: Blockstore> {
Expand Down
3 changes: 1 addition & 2 deletions core/hamt-ipld/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! A implementation of `ipld hamt` in Rust.

#![allow(clippy::bool_comparison, clippy::type_complexity, clippy::or_fun_call)]
#![feature(specialization)]

mod error;
mod hash;
Expand All @@ -12,5 +11,5 @@ pub mod node;
#[cfg(test)]
mod tests;

pub use self::ipld::{cst_from_bstore, BasicCborIpldStore, Blockstore, CborIpldStore, HasCid};
pub use self::ipld::{cst_from_bstore, BasicCborIpldStore, Blockstore, CborIpldStore};
pub use self::node::{Hamt, DEFAULT_BIT_WIDTH};
11 changes: 9 additions & 2 deletions core/hamt-ipld/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ pub struct Node {
items: RefCell<Vec<Item>>,
}

#[cfg(not(feature = "nightly"))]
impl<'a> cid_ext::HasCid for &'a Node {
fn has_cid(&self) -> Option<&Cid> {
None
}
}

#[inline]
pub fn set_bit(input: &mut U256, n: u32) {
let one: U256 = 1.into();
Expand Down Expand Up @@ -394,7 +401,7 @@ impl Node {
for item in &mut items[..].iter_mut() {
if let Item::Ptr(node) = item {
node.flush(bs)?;
let cid = bs.put(&node)?;
let cid = bs.put(&**node)?;
// flush current item
*item = Item::Link(cid);
}
Expand All @@ -407,7 +414,7 @@ impl Node {
where
B: CborIpldStore,
{
let cid = bs.put(&self)?;
let cid = bs.put(&*self)?;
let node: Node = bs.get(&cid)?;
let mut total_size = ipld_cbor::dump_object(&node)?.len() as u64;
for item in self.items.borrow_mut().iter_mut() {
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
nightly-2019-12-20