From 0f205ee45a13355c281f2263c0f8d72d95e0041a Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 17:02:26 -0700 Subject: [PATCH 1/9] update cid to latest version v0.11.1 released Mar 1, 2024 --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index b550976f..620875eb 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -15,7 +15,7 @@ arb = ["quickcheck", "cid/arb"] [dependencies] anyhow = { version = "1.0.40", default-features = false } -cid = { version = "0.10.0", default-features = false, features = ["alloc"] } +cid = { version = "0.11.1", default-features = false, features = ["alloc"] } core2 = { version = "0.4", default-features = false, features = ["alloc"] } multihash = { version = "0.18.0", default-features = false, features = ["alloc"] } From 967d4176bc0111e48a030960a34adc4831174da4 Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 17:40:20 -0700 Subject: [PATCH 2/9] update codebase to support cid version 0.11.1 --- Cargo.toml | 2 +- core/Cargo.toml | 4 ++-- core/src/ipld.rs | 4 ++-- dag-cbor-derive/src/attr.rs | 2 ++ dag-cbor/Cargo.toml | 2 +- dag-cbor/src/encode.rs | 20 ++++++++++---------- dag-json/src/codec.rs | 2 +- dag-pb/src/codec.rs | 2 +- macro/Cargo.toml | 2 +- src/block.rs | 19 +++++++++++++++---- src/lib.rs | 3 ++- src/path.rs | 16 +++++++++------- 12 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4689b5d3..fb01e719 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ libipld-json = { version = "0.16.0", path = "dag-json", optional = true } libipld-macro = { version = "0.16.0", path = "macro" } libipld-pb = { version = "0.16.0", path = "dag-pb", optional = true } log = "0.4.14" -multihash = { version = "0.18.0", default-features = false, features = ["multihash-impl"] } +multihash = { version = "0.18.1", default-features = false, features = ["alloc"] } thiserror = "1.0.25" [dev-dependencies] diff --git a/core/Cargo.toml b/core/Cargo.toml index 620875eb..70b29ff0 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,7 @@ arb = ["quickcheck", "cid/arb"] anyhow = { version = "1.0.40", default-features = false } cid = { version = "0.11.1", default-features = false, features = ["alloc"] } core2 = { version = "0.4", default-features = false, features = ["alloc"] } -multihash = { version = "0.18.0", default-features = false, features = ["alloc"] } +multihash = { version = "0.18.1", default-features = false, features = ["alloc"] } multibase = { version = "0.9.1", default-features = false, optional = true } serde = { version = "1.0.132", default-features = false, features = ["alloc"], optional = true } @@ -25,7 +25,7 @@ thiserror = {version = "1.0.25", optional = true } quickcheck = { version = "1.0", optional = true } [dev-dependencies] -multihash = { version = "0.18.0", default-features = false, features = ["multihash-impl", "blake3"] } +multihash = { version = "0.18.1", default-features = false } serde_test = "1.0.132" serde_bytes = "0.11.5" serde_json = "1.0.79" diff --git a/core/src/ipld.rs b/core/src/ipld.rs index 68fb80a9..2a89a21a 100644 --- a/core/src/ipld.rs +++ b/core/src/ipld.rs @@ -75,13 +75,13 @@ pub enum IpldIndex<'a> { MapRef(&'a str), } -impl<'a> From for IpldIndex<'a> { +impl From for IpldIndex<'_> { fn from(index: usize) -> Self { Self::List(index) } } -impl<'a> From for IpldIndex<'a> { +impl From for IpldIndex<'_> { fn from(key: String) -> Self { Self::Map(key) } diff --git a/dag-cbor-derive/src/attr.rs b/dag-cbor-derive/src/attr.rs index e8431ca0..f8330cc4 100644 --- a/dag-cbor-derive/src/attr.rs +++ b/dag-cbor-derive/src/attr.rs @@ -10,6 +10,7 @@ mod kw { custom_keyword!(default); } +#[allow(dead_code)] #[derive(Debug)] pub struct Attrs { pub paren: syn::token::Paren, @@ -25,6 +26,7 @@ impl Parse for Attrs { } } +#[allow(dead_code)] #[derive(Debug)] pub struct Attr { pub key: K, diff --git a/dag-cbor/Cargo.toml b/dag-cbor/Cargo.toml index 3cac8d39..4f012a52 100644 --- a/dag-cbor/Cargo.toml +++ b/dag-cbor/Cargo.toml @@ -15,6 +15,6 @@ thiserror = "1.0.25" [dev-dependencies] hex = "0.4.3" libipld-macro = { path = "../macro" } -multihash = "0.17.0" +multihash = "0.18.1" quickcheck = "1.0.3" serde_cbor = { version = "0.11.1", features = ["tags"] } diff --git a/dag-cbor/src/encode.rs b/dag-cbor/src/encode.rs index 37c6ef51..f1110344 100644 --- a/dag-cbor/src/encode.rs +++ b/dag-cbor/src/encode.rs @@ -27,10 +27,10 @@ pub fn write_null(w: &mut W) -> Result<()> { pub fn write_u8(w: &mut W, major: MajorKind, value: u8) -> Result<()> { let major = major as u8; if value <= 0x17 { - let buf = [major << 5 | value]; + let buf = [(major << 5) | value]; w.write_all(&buf)?; } else { - let buf = [major << 5 | 24, value]; + let buf = [(major << 5) | 24, value]; w.write_all(&buf)?; } Ok(()) @@ -38,10 +38,10 @@ pub fn write_u8(w: &mut W, major: MajorKind, value: u8) -> Result<()> /// Writes a u16 to a cbor encoded byte stream. pub fn write_u16(w: &mut W, major: MajorKind, value: u16) -> Result<()> { - if value <= u16::from(u8::max_value()) { + if value <= u16::from(u8::MAX) { write_u8(w, major, value as u8)?; } else { - let mut buf = [(major as u8) << 5 | 25, 0, 0]; + let mut buf = [((major as u8) << 5) | 25, 0, 0]; BigEndian::write_u16(&mut buf[1..], value); w.write_all(&buf)?; } @@ -50,10 +50,10 @@ pub fn write_u16(w: &mut W, major: MajorKind, value: u16) -> Result<() /// Writes a u32 to a cbor encoded byte stream. pub fn write_u32(w: &mut W, major: MajorKind, value: u32) -> Result<()> { - if value <= u32::from(u16::max_value()) { + if value <= u32::from(u16::MAX) { write_u16(w, major, value as u16)?; } else { - let mut buf = [(major as u8) << 5 | 26, 0, 0, 0, 0]; + let mut buf = [((major as u8) << 5) | 26, 0, 0, 0, 0]; BigEndian::write_u32(&mut buf[1..], value); w.write_all(&buf)?; } @@ -62,10 +62,10 @@ pub fn write_u32(w: &mut W, major: MajorKind, value: u32) -> Result<() /// Writes a u64 to a cbor encoded byte stream. pub fn write_u64(w: &mut W, major: MajorKind, value: u64) -> Result<()> { - if value <= u64::from(u32::max_value()) { + if value <= u64::from(u32::MAX) { write_u32(w, major, value as u32)?; } else { - let mut buf = [(major as u8) << 5 | 27, 0, 0, 0, 0, 0, 0, 0, 0]; + let mut buf = [((major as u8) << 5) | 27, 0, 0, 0, 0, 0, 0, 0, 0]; BigEndian::write_u64(&mut buf[1..], value); w.write_all(&buf)?; } @@ -224,12 +224,12 @@ impl Encode for String { impl Encode for i128 { fn encode(&self, _: DagCbor, w: &mut W) -> Result<()> { if *self < 0 { - if -(*self + 1) > u64::max_value() as i128 { + if -(*self + 1) > u64::MAX as i128 { return Err(NumberOutOfRange::new::().into()); } write_u64(w, MajorKind::NegativeInt, -(*self + 1) as u64)?; } else { - if *self > u64::max_value() as i128 { + if *self > u64::MAX as i128 { return Err(NumberOutOfRange::new::().into()); } write_u64(w, MajorKind::UnsignedInt, *self as u64)?; diff --git a/dag-json/src/codec.rs b/dag-json/src/codec.rs index 0d97be04..0b39d3e0 100644 --- a/dag-json/src/codec.rs +++ b/dag-json/src/codec.rs @@ -62,7 +62,7 @@ fn deserialize<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result(&'a Ipld); -impl<'a> Serialize for Wrapper<'a> { +impl Serialize for Wrapper<'_> { fn serialize(&self, serializer: S) -> Result where S: ser::Serializer, diff --git a/dag-pb/src/codec.rs b/dag-pb/src/codec.rs index 4fe10dbc..06a8391d 100644 --- a/dag-pb/src/codec.rs +++ b/dag-pb/src/codec.rs @@ -258,7 +258,7 @@ impl MessageWrite for PbLink { size += 1 + sizeof_len(l); if let Some(ref name) = self.name { - size += 1 + sizeof_len(name.as_bytes().len()); + size += 1 + sizeof_len(name.len()); } if let Some(tsize) = self.size { diff --git a/macro/Cargo.toml b/macro/Cargo.toml index f78b97f9..3def44ef 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -11,4 +11,4 @@ repository = "https://github.com/ipfs-rust/rust-ipld" libipld-core = { version = "0.16.0", path = "../core" } [dev-dependencies] -multihash = { version = "0.18.0", features = ["blake3"] } +multihash = { version = "0.18.1" } diff --git a/src/block.rs b/src/block.rs index 8eec9ce9..c6203723 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,5 +1,5 @@ //! Block validation -use crate::cid::Cid; +use crate::cid::{self, Cid}; use crate::codec::{Codec, Decode, Encode, References}; use crate::error::{BlockTooLarge, InvalidMultihash, Result, UnsupportedMultihash}; use crate::ipld::Ipld; @@ -81,6 +81,14 @@ fn verify_cid, const S: usize>(cid: &Cid, payload: &[u8]) Ok(()) } +// Helper function to create a CID with the correct multihash version +fn create_cid(codec: u64, mh_bytes: &[u8]) -> Result { + // Convert via the raw bytes + let mh = cid::multihash::Multihash::from_bytes(mh_bytes) + .map_err(|_| InvalidMultihash(mh_bytes.to_vec()))?; + Ok(Cid::new_v1(codec, mh)) +} + impl Block { /// Creates a new block. Returns an error if the hash doesn't match /// the data. @@ -114,13 +122,14 @@ impl Block { } /// Encode a block.` - pub fn encode + ?Sized>( + pub fn encode( codec: CE, hcode: S::Hashes, payload: &T, ) -> Result where - CE: Into, + CE: Codec + Into, + T: Encode + ?Sized, { debug_assert_eq!( Into::::into(codec), @@ -131,7 +140,9 @@ impl Block { return Err(BlockTooLarge(data.len()).into()); } let mh = hcode.digest(&data); - let cid = Cid::new_v1(codec.into(), mh); + // Convert multihash to bytes and create CID using our helper + let mh_bytes = mh.to_bytes(); + let cid = create_cid::<64>(codec.into(), &mh_bytes)?; Ok(Self { _marker: PhantomData, cid, diff --git a/src/lib.rs b/src/lib.rs index b9b26978..e9cde6b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub use codec_impl::IpldCodec; pub use error::Result; pub use ipld::Ipld; pub use link::Link; -pub use multihash::Multihash; +// Don't re-export multihash to avoid version conflicts +// pub use multihash::Multihash; pub use path::{DagPath, Path}; pub use store::DefaultParams; diff --git a/src/path.rs b/src/path.rs index 40dac980..7e51799f 100644 --- a/src/path.rs +++ b/src/path.rs @@ -45,15 +45,17 @@ impl From for Path { } } -impl ToString for Path { - fn to_string(&self) -> String { - let mut path = "".to_string(); +impl core::fmt::Display for Path { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut first = true; for seg in &self.0 { - path.push_str(seg.as_str()); - path.push('/'); + if !first { + write!(f, "/")?; + } + write!(f, "{}", seg)?; + first = false; } - path.pop(); - path + Ok(()) } } From 46d42991dbb1960601c069faec1fe7de100aeaeb Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 18:28:27 -0700 Subject: [PATCH 3/9] cargo machete --- Cargo.toml | 5 ++--- core/Cargo.toml | 4 ++-- dag-json/Cargo.toml | 1 - dag-pb/Cargo.toml | 3 +-- macro/Cargo.toml | 2 +- src/block.rs | 6 +++--- src/store.rs | 4 ++-- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb01e719..5c1b57b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,10 @@ libipld-core = { version = "0.16.0", path = "core" } libipld-json = { version = "0.16.0", path = "dag-json", optional = true } libipld-macro = { version = "0.16.0", path = "macro" } libipld-pb = { version = "0.16.0", path = "dag-pb", optional = true } -log = "0.4.14" -multihash = { version = "0.18.1", default-features = false, features = ["alloc"] } -thiserror = "1.0.25" +multihash-codetable = "0.1.4" [dev-dependencies] +multihash-codetable = { version = "0.1.4", features = ["blake3"] } async-std = { version = "1.9.0", features = ["attributes"] } criterion = "0.3.4" proptest = "1.0.0" diff --git a/core/Cargo.toml b/core/Cargo.toml index 70b29ff0..aaab07d4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,7 @@ arb = ["quickcheck", "cid/arb"] anyhow = { version = "1.0.40", default-features = false } cid = { version = "0.11.1", default-features = false, features = ["alloc"] } core2 = { version = "0.4", default-features = false, features = ["alloc"] } -multihash = { version = "0.18.1", default-features = false, features = ["alloc"] } +multihash = { version = "0.19.3", default-features = false, features = ["alloc"] } multibase = { version = "0.9.1", default-features = false, optional = true } serde = { version = "1.0.132", default-features = false, features = ["alloc"], optional = true } @@ -25,7 +25,7 @@ thiserror = {version = "1.0.25", optional = true } quickcheck = { version = "1.0", optional = true } [dev-dependencies] -multihash = { version = "0.18.1", default-features = false } +multihash = { version = "0.19.3", default-features = false } serde_test = "1.0.132" serde_bytes = "0.11.5" serde_json = "1.0.79" diff --git a/dag-json/Cargo.toml b/dag-json/Cargo.toml index cd043c69..06eb57e3 100644 --- a/dag-json/Cargo.toml +++ b/dag-json/Cargo.toml @@ -9,6 +9,5 @@ repository = "https://github.com/ipfs-rust/rust-ipld" [dependencies] libipld-core = { version = "0.16.0", path = "../core" } -multihash = "0.18.0" serde_json = { version = "1.0.64", features = ["float_roundtrip"] } serde = { version = "1.0.126", features = ["derive"] } diff --git a/dag-pb/Cargo.toml b/dag-pb/Cargo.toml index 3ddf1d18..c48d6aef 100644 --- a/dag-pb/Cargo.toml +++ b/dag-pb/Cargo.toml @@ -9,12 +9,11 @@ repository = "https://github.com/ipfs-rust/rust-ipld" [dependencies] libipld-core = { version = "0.16.0", path = "../core" } -thiserror = "1.0.25" quick-protobuf = "0.8.1" bytes = "1.3.0" [dev-dependencies] libipld-macro = { path = "../macro" } libipld = { path = "../" } -multihash = "0.18.0" +multihash = "0.19.3" hex = "0.4.3" diff --git a/macro/Cargo.toml b/macro/Cargo.toml index 3def44ef..a40578b2 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -11,4 +11,4 @@ repository = "https://github.com/ipfs-rust/rust-ipld" libipld-core = { version = "0.16.0", path = "../core" } [dev-dependencies] -multihash = { version = "0.18.1" } +multihash = { version = "0.19.3" } diff --git a/src/block.rs b/src/block.rs index c6203723..4ff8489b 100644 --- a/src/block.rs +++ b/src/block.rs @@ -3,7 +3,7 @@ use crate::cid::{self, Cid}; use crate::codec::{Codec, Decode, Encode, References}; use crate::error::{BlockTooLarge, InvalidMultihash, Result, UnsupportedMultihash}; use crate::ipld::Ipld; -use crate::multihash::MultihashDigest; +use multihash_codetable::MultihashDigest; use crate::store::StoreParams; use core::borrow::Borrow; use core::convert::TryFrom; @@ -160,7 +160,7 @@ impl Block { /// use libipld::block::Block; /// use libipld::cbor::DagCborCodec; /// use libipld::ipld::Ipld; - /// use libipld::multihash::Code; + /// use multihash_codetable::Code; /// use libipld::store::DefaultParams; /// /// let block = @@ -204,7 +204,7 @@ mod tests { use crate::codec_impl::IpldCodec; use crate::ipld; use crate::ipld::Ipld; - use crate::multihash::Code; + use multihash_codetable::Code; use crate::store::DefaultParams; use fnv::FnvHashSet; diff --git a/src/store.rs b/src/store.rs index e4894f60..6a041075 100644 --- a/src/store.rs +++ b/src/store.rs @@ -17,7 +17,7 @@ //! incrementally deleting unaliased blocks until the size target is no longer exceeded. It is //! implementation defined in which order unaliased blocks get removed. use crate::codec::Codec; -use crate::multihash::MultihashDigest; +use multihash_codetable::{MultihashDigest, Code}; /// The store parameters. pub trait StoreParams: std::fmt::Debug + Clone + Send + Sync + Unpin + 'static { @@ -36,5 +36,5 @@ pub struct DefaultParams; impl StoreParams for DefaultParams { const MAX_BLOCK_SIZE: usize = 1_048_576; type Codecs = crate::IpldCodec; - type Hashes = crate::multihash::Code; + type Hashes = Code; } From 1a6119e1810911c016009ef3e6ecb1f923e611f9 Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 18:31:20 -0700 Subject: [PATCH 4/9] cargo fmt --- src/block.rs | 10 +++------- src/store.rs | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/block.rs b/src/block.rs index 4ff8489b..c26b634c 100644 --- a/src/block.rs +++ b/src/block.rs @@ -3,12 +3,12 @@ use crate::cid::{self, Cid}; use crate::codec::{Codec, Decode, Encode, References}; use crate::error::{BlockTooLarge, InvalidMultihash, Result, UnsupportedMultihash}; use crate::ipld::Ipld; -use multihash_codetable::MultihashDigest; use crate::store::StoreParams; use core::borrow::Borrow; use core::convert::TryFrom; use core::marker::PhantomData; use core::ops::Deref; +use multihash_codetable::MultihashDigest; /// Block #[derive(Clone)] @@ -122,11 +122,7 @@ impl Block { } /// Encode a block.` - pub fn encode( - codec: CE, - hcode: S::Hashes, - payload: &T, - ) -> Result + pub fn encode(codec: CE, hcode: S::Hashes, payload: &T) -> Result where CE: Codec + Into, T: Encode + ?Sized, @@ -204,9 +200,9 @@ mod tests { use crate::codec_impl::IpldCodec; use crate::ipld; use crate::ipld::Ipld; - use multihash_codetable::Code; use crate::store::DefaultParams; use fnv::FnvHashSet; + use multihash_codetable::Code; type IpldBlock = Block; diff --git a/src/store.rs b/src/store.rs index 6a041075..ac1d270b 100644 --- a/src/store.rs +++ b/src/store.rs @@ -17,7 +17,7 @@ //! incrementally deleting unaliased blocks until the size target is no longer exceeded. It is //! implementation defined in which order unaliased blocks get removed. use crate::codec::Codec; -use multihash_codetable::{MultihashDigest, Code}; +use multihash_codetable::{Code, MultihashDigest}; /// The store parameters. pub trait StoreParams: std::fmt::Debug + Clone + Send + Sync + Unpin + 'static { From 4f4d824e5c16aa95569b4928d3cb99dd79f6cb48 Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 18:39:12 -0700 Subject: [PATCH 5/9] multihash updates for testing --- dag-cbor/Cargo.toml | 2 +- dag-cbor/src/lib.rs | 2 +- dag-json/Cargo.toml | 1 + dag-json/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dag-cbor/Cargo.toml b/dag-cbor/Cargo.toml index 4f012a52..8f6462e5 100644 --- a/dag-cbor/Cargo.toml +++ b/dag-cbor/Cargo.toml @@ -15,6 +15,6 @@ thiserror = "1.0.25" [dev-dependencies] hex = "0.4.3" libipld-macro = { path = "../macro" } -multihash = "0.18.1" +multihash-codetable = { version = "0.1.4", features = ["blake3"] } quickcheck = "1.0.3" serde_cbor = { version = "0.11.1", features = ["tags"] } diff --git a/dag-cbor/src/lib.rs b/dag-cbor/src/lib.rs index 00cf7547..5c7021ab 100644 --- a/dag-cbor/src/lib.rs +++ b/dag-cbor/src/lib.rs @@ -42,7 +42,7 @@ mod tests { use libipld_core::cid::Cid; use libipld_core::codec::assert_roundtrip; use libipld_core::ipld::Ipld; - use libipld_core::multihash::{Code, MultihashDigest}; + use multihash_codetable::{Code, MultihashDigest}; use libipld_macro::ipld; use std::collections::HashSet; diff --git a/dag-json/Cargo.toml b/dag-json/Cargo.toml index 06eb57e3..46eea5b3 100644 --- a/dag-json/Cargo.toml +++ b/dag-json/Cargo.toml @@ -11,3 +11,4 @@ repository = "https://github.com/ipfs-rust/rust-ipld" libipld-core = { version = "0.16.0", path = "../core" } serde_json = { version = "1.0.64", features = ["float_roundtrip"] } serde = { version = "1.0.126", features = ["derive"] } +multihash-codetable = { version = "0.1.4", features = ["blake3"] } diff --git a/dag-json/src/lib.rs b/dag-json/src/lib.rs index b22d5b83..2c28f942 100644 --- a/dag-json/src/lib.rs +++ b/dag-json/src/lib.rs @@ -60,7 +60,7 @@ impl References for Ipld { mod tests { use super::*; use libipld_core::cid::Cid; - use libipld_core::multihash::{Code, MultihashDigest}; + use multihash_codetable::{Code, MultihashDigest}; use std::collections::BTreeMap; #[test] From cee139b271b6a624768f96c0671ea9fe60446012 Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 18:52:59 -0700 Subject: [PATCH 6/9] try to fix the clippy issue --- core/Cargo.toml | 2 +- core/src/ipld.rs | 2 +- core/src/serde/ser.rs | 44 +++++++++++++++++++++---------------------- dag-pb/Cargo.toml | 2 +- dag-pb/src/lib.rs | 2 +- macro/Cargo.toml | 1 + macro/src/lib.rs | 2 +- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index aaab07d4..4b234680 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -25,7 +25,7 @@ thiserror = {version = "1.0.25", optional = true } quickcheck = { version = "1.0", optional = true } [dev-dependencies] -multihash = { version = "0.19.3", default-features = false } +multihash-codetable = { version = "0.1.4", features = ["blake3"] } serde_test = "1.0.132" serde_bytes = "0.11.5" serde_json = "1.0.79" diff --git a/core/src/ipld.rs b/core/src/ipld.rs index 2a89a21a..3a9fab0e 100644 --- a/core/src/ipld.rs +++ b/core/src/ipld.rs @@ -195,7 +195,7 @@ impl<'a> Iterator for IpldIter<'a> { mod tests { use super::*; use crate::cid::Cid; - use crate::multihash::{Code, MultihashDigest}; + use multihash_codetable::{Code, MultihashDigest}; #[test] fn test_ipld_bool_from() { diff --git a/core/src/serde/ser.rs b/core/src/serde/ser.rs index 760b8c09..6af736a8 100644 --- a/core/src/serde/ser.rs +++ b/core/src/serde/ser.rs @@ -208,13 +208,13 @@ impl serde::Serializer for Serializer { } #[inline] - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, name: &'static str, value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let ipld = value.serialize(self); if name == CID_SERDE_PRIVATE_IDENTIFIER { @@ -227,7 +227,7 @@ impl serde::Serializer for Serializer { ipld } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -235,7 +235,7 @@ impl serde::Serializer for Serializer { value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let values = BTreeMap::from([(variant.to_owned(), value.serialize(self)?)]); Ok(Self::Ok::Map(values)) @@ -247,9 +247,9 @@ impl serde::Serializer for Serializer { } #[inline] - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } @@ -342,9 +342,9 @@ impl ser::SerializeSeq for SerializeVec { type Ok = Ipld; type Error = SerdeError; - fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.vec.push(value.serialize(Serializer)?); Ok(()) @@ -359,9 +359,9 @@ impl ser::SerializeTuple for SerializeVec { type Ok = Ipld; type Error = SerdeError; - fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -375,9 +375,9 @@ impl ser::SerializeTupleStruct for SerializeVec { type Ok = Ipld; type Error = SerdeError; - fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -391,9 +391,9 @@ impl ser::SerializeTupleVariant for SerializeTupleVariant { type Ok = Ipld; type Error = SerdeError; - fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.vec.push(value.serialize(Serializer)?); Ok(()) @@ -409,9 +409,9 @@ impl ser::SerializeMap for SerializeMap { type Ok = Ipld; type Error = SerdeError; - fn serialize_key(&mut self, key: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, key: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { match key.serialize(Serializer)? { Ipld::String(string_key) => { @@ -422,9 +422,9 @@ impl ser::SerializeMap for SerializeMap { } } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let key = self.next_key.take(); // Panic because this indicates a bug in the program rather than an @@ -443,13 +443,13 @@ impl ser::SerializeStruct for SerializeMap { type Ok = Ipld; type Error = SerdeError; - fn serialize_field( + fn serialize_field( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { serde::ser::SerializeMap::serialize_key(self, key)?; serde::ser::SerializeMap::serialize_value(self, value) @@ -464,13 +464,13 @@ impl ser::SerializeStructVariant for SerializeStructVariant { type Ok = Ipld; type Error = SerdeError; - fn serialize_field( + fn serialize_field( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.map .insert(key.to_string(), value.serialize(Serializer)?); diff --git a/dag-pb/Cargo.toml b/dag-pb/Cargo.toml index c48d6aef..296ab229 100644 --- a/dag-pb/Cargo.toml +++ b/dag-pb/Cargo.toml @@ -15,5 +15,5 @@ bytes = "1.3.0" [dev-dependencies] libipld-macro = { path = "../macro" } libipld = { path = "../" } -multihash = "0.19.3" +multihash-codetable = { version = "0.1.4", features = ["blake3"] } hex = "0.4.3" diff --git a/dag-pb/src/lib.rs b/dag-pb/src/lib.rs index 960713a7..0fd5b846 100644 --- a/dag-pb/src/lib.rs +++ b/dag-pb/src/lib.rs @@ -67,7 +67,7 @@ impl References for Ipld { mod tests { use super::*; use libipld_core::cid::Cid; - use libipld_core::multihash::{Code, MultihashDigest}; + use multihash_codetable::{Code, MultihashDigest}; use std::collections::BTreeMap; #[test] diff --git a/macro/Cargo.toml b/macro/Cargo.toml index a40578b2..0479c5b4 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -12,3 +12,4 @@ libipld-core = { version = "0.16.0", path = "../core" } [dev-dependencies] multihash = { version = "0.19.3" } +multihash-codetable = { version = "0.1.4", features = ["blake3"] } diff --git a/macro/src/lib.rs b/macro/src/lib.rs index b998b355..682979bb 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -293,7 +293,7 @@ macro_rules! ipld_unexpected { mod tests { use super::*; use libipld_core::cid::Cid; - use libipld_core::multihash::{Code, MultihashDigest}; + use multihash_codetable::{Code, MultihashDigest}; #[test] fn test_macro() { From 104230428284dfcb5e839cb68b5a8991807042ff Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 19:04:51 -0700 Subject: [PATCH 7/9] remove extra dev dependency --- macro/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/macro/Cargo.toml b/macro/Cargo.toml index 0479c5b4..023df516 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -11,5 +11,4 @@ repository = "https://github.com/ipfs-rust/rust-ipld" libipld-core = { version = "0.16.0", path = "../core" } [dev-dependencies] -multihash = { version = "0.19.3" } multihash-codetable = { version = "0.1.4", features = ["blake3"] } From 2edfbc9f564c839feab357d44f21a73b699e9f8c Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 20:14:21 -0700 Subject: [PATCH 8/9] cargo fmt and add the #[allow(dependency_on_unit_never_type_fallback)] --- core/src/serde/ser.rs | 12 ++---------- dag-cbor-derive/src/lib.rs | 2 ++ dag-cbor/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/core/src/serde/ser.rs b/core/src/serde/ser.rs index 6af736a8..fff7298c 100644 --- a/core/src/serde/ser.rs +++ b/core/src/serde/ser.rs @@ -443,11 +443,7 @@ impl ser::SerializeStruct for SerializeMap { type Ok = Ipld; type Error = SerdeError; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), Self::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where T: ser::Serialize + ?Sized, { @@ -464,11 +460,7 @@ impl ser::SerializeStructVariant for SerializeStructVariant { type Ok = Ipld; type Error = SerdeError; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), Self::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where T: ser::Serialize + ?Sized, { diff --git a/dag-cbor-derive/src/lib.rs b/dag-cbor-derive/src/lib.rs index 25c0f453..068c6324 100644 --- a/dag-cbor-derive/src/lib.rs +++ b/dag-cbor-derive/src/lib.rs @@ -19,7 +19,9 @@ fn dag_cbor_derive(s: Structure) -> TokenStream { let encode = gen::gen_encode(&ast, &libipld); let decode = gen::gen_decode(&ast, &libipld); quote! { + #[allow(dependency_on_unit_never_type_fallback)] #encode + #[allow(dependency_on_unit_never_type_fallback)] #decode } } diff --git a/dag-cbor/src/lib.rs b/dag-cbor/src/lib.rs index 5c7021ab..43b4a95b 100644 --- a/dag-cbor/src/lib.rs +++ b/dag-cbor/src/lib.rs @@ -42,8 +42,8 @@ mod tests { use libipld_core::cid::Cid; use libipld_core::codec::assert_roundtrip; use libipld_core::ipld::Ipld; - use multihash_codetable::{Code, MultihashDigest}; use libipld_macro::ipld; + use multihash_codetable::{Code, MultihashDigest}; use std::collections::HashSet; #[test] From 28e0fb2202a4714fe13236486bc6246902eb6601 Mon Sep 17 00:00:00 2001 From: Clinton Bowen Date: Wed, 14 May 2025 20:17:30 -0700 Subject: [PATCH 9/9] update hecrj/setup-rust-action@v2 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb90c2f..b24dcce0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: run: choco install llvm - name: Install rust toolchain - uses: hecrj/setup-rust-action@v1 + uses: hecrj/setup-rust-action@v2 with: rust-version: ${{ matrix.toolchain.rust }} targets: ${{ matrix.platform.target }} @@ -114,7 +114,7 @@ jobs: key: lint-cargo - name: Install rust toolchain - uses: hecrj/setup-rust-action@v1 + uses: hecrj/setup-rust-action@v2 with: rust-version: stable components: clippy, rustfmt