Skip to content

Commit

Permalink
feat: upgrade rust-cid and use use ipld-core
Browse files Browse the repository at this point in the history
Intead of relying on libipld-core, use ipld-core instead. This also enables
the upgrade to rust-cid v0.11.
  • Loading branch information
vmx committed Feb 23, 2024
1 parent ffae329 commit 0b98bf5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ edition = "2018"

[dependencies]
cbor4ii = { version = "0.2.14", default-features = false, features = ["use_alloc"] }
cid = { version = "0.10.1", default-features = false, features = ["serde-codec"] }
cid = { version = "0.11.0", default-features = false, features = ["serde-codec"] }
scopeguard = "1.1.0"
serde = { version = "1.0.164", default-features = false, features = ["alloc"] }

[dev-dependencies]
ipld-core = { version = "0.2.0", features = ["serde"] }
serde_derive = { version = "1.0.164", default-features = false }
libipld-core = { version = "0.16.0", default-features = false, features = ["serde-codec"] }
serde_bytes = { version = "0.11.9", default-features = false, features = ["alloc"]}

[features]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Serde IPLD DAG-CBOR
[![Crates.io](https://img.shields.io/crates/v/serde_ipld_dag_cbor.svg)](https://crates.io/crates/serde_ipld_dagcbor)
[![Documentation](https://docs.rs/serde_ipld_dag_cbor/badge.svg)](https://docs.rs/serde_ipld_dag_cbor)

This is a [Serde] implementation for [DAG-CBOR]. It can be use in conjunction with [libipld].
This is a [Serde] implementation for [DAG-CBOR]. It can be use in conjunction with [ipld-core].

The underlying library for CBOR encoding/decoding is [cbor4ii] and the Serde implementation is also heavily based on their code.

This crate started as a fork of [serde_cbor], thanks everyone involved there.

[Serde]: https://github.com/serde-rs/serde
[DAG-CBOR]: https://ipld.io/specs/codecs/dag-cbor/spec/
[libipld]: https://github.com/ipld/libipld
[ipld-core]: https://github.com/vmx/ipld-core
[cbor4ii]: https://github.com/quininer/cbor4ii
[serde_cbor]: https://github.com/pyfisch/cbor

Expand Down
3 changes: 2 additions & 1 deletion examples/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
use std::convert::{TryFrom, TryInto};

use cid::Cid;
use libipld_core::ipld::Ipld;
use ipld_core::ipld::Ipld;
use serde::{de, Deserialize};
use serde_bytes::ByteBuf;
use serde_derive::Deserialize;
use serde_ipld_dagcbor::from_slice;

/// The CID `bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy` encoded as CBOR
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! ```
//!
//! There are a lot of options available to customize the format.
//! To operate on untyped DAG-CBOR values have a look at the [`libipld_core::ipld::Ipld`] type.
//! To operate on untyped DAG-CBOR values have a look at the [`ipld_core::ipld::Ipld`] type.
//!
//! # Type-based Serialization and Deserialization
//! Serde provides a mechanism for low boilerplate serialization & deserialization of values to and
Expand All @@ -70,7 +70,7 @@
//!
//! ```rust
//! use serde_ipld_dagcbor::from_slice;
//! use libipld_core::ipld::Ipld;
//! use ipld_core::ipld::Ipld;
//!
//! let slice = b"\x82\x01\xa1aaab";
//! let value: Ipld = from_slice(slice).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::io::Cursor;
use std::str::FromStr;

use cid::Cid;
use libipld_core::ipld::Ipld;
use ipld_core::ipld::Ipld;
use serde::de;
use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;
use serde_derive::{Deserialize, Serialize};
use serde_ipld_dagcbor::{from_reader, from_slice, to_vec};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/de.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use libipld_core::ipld::Ipld;
use ipld_core::ipld::Ipld;
use serde_ipld_dagcbor::{de, to_vec, DecodeError};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/enum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};

use serde_ipld_dagcbor::{from_slice, to_vec, DecodeError};

Expand Down
8 changes: 4 additions & 4 deletions tests/ipld.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use libipld_core::ipld::Ipld;
use serde::{Deserialize, Serialize};
use ipld_core::ipld::Ipld;
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
struct TupleStruct(String, i32, u64);
Expand Down Expand Up @@ -50,7 +50,7 @@ fn serde() {
array,
};

let ipld = libipld_core::serde::to_ipld(data.clone()).unwrap();
let ipld = ipld_core::serde::to_ipld(data.clone()).unwrap();
println!("{:?}", ipld);

let data_ser = serde_ipld_dagcbor::to_vec(&ipld).unwrap();
Expand All @@ -74,7 +74,7 @@ fn serde() {
#[test]
fn unit_struct_not_supported() {
let unit_array = vec![UnitStruct, UnitStruct, UnitStruct];
let ipld = libipld_core::serde::to_ipld(unit_array);
let ipld = ipld_core::serde::to_ipld(unit_array);
assert!(ipld.is_err());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/std_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};

use serde_ipld_dagcbor::{from_slice, to_vec};

Expand Down

0 comments on commit 0b98bf5

Please sign in to comment.