{"id":20642403,"url":"https://github.com/ipld/rust-ipld-core","last_synced_at":"2025-04-16T01:38:01.163Z","repository":{"id":219115838,"uuid":"748243206","full_name":"ipld/rust-ipld-core","owner":"ipld","description":"This crate provides core types for interoperating with IPLD.","archived":false,"fork":false,"pushed_at":"2025-02-13T01:28:03.000Z","size":156,"stargazers_count":12,"open_issues_count":5,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-25T09:51:21.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-25T15:18:12.000Z","updated_at":"2025-03-14T10:31:57.000Z","dependencies_parsed_at":"2024-01-25T15:30:53.106Z","dependency_job_id":"cfb20628-6a7b-49cd-a895-1fb95bcfb127","html_url":"https://github.com/ipld/rust-ipld-core","commit_stats":null,"previous_names":["vmx/ipld-core","ipld/rust-ipld-core"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Frust-ipld-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Frust-ipld-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Frust-ipld-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Frust-ipld-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipld","download_url":"https://codeload.github.com/ipld/rust-ipld-core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249182786,"owners_count":21226123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T16:08:59.250Z","updated_at":"2025-04-16T01:38:01.146Z","avatar_url":"https://github.com/ipld.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"IPLD core\n=========\n\n[![Crates.io](https://img.shields.io/crates/v/ipld-core.svg)](https://crates.io/crates/ipld-core)\n[![Documentation](https://docs.rs/ipld-core/badge.svg)](https://docs.rs/ipld-core)\n\nThis crate provides core types for interoperating with [IPLD]. Codecs are not part of this crate, they are independent, but rely on `ipld-core`.\n\nThe code is based on [libipld-core]. The major difference is that [Serde] is used a lot more for better interoperability with the rest of the Rust ecosystem.\n\n\nUsage\n-----\n\n### Codec independent code\n\nOne of the main features of IPLD is that your Codec is independent of the data you are encoding. Hence it's common that you want to have  your code to be independent of a specific code, but rather be generic.\n\nHere's a full example of a function that can encode data with both [serde_ipld_dagcbor] or [serde_ipld_dagjson]:\n\n```rust\nuse std::str;\n\nuse ipld_core::codec::Codec;\nuse serde::{Deserialize, Serialize};\nuse serde_ipld_dagcbor::codec::DagCborCodec;\nuse serde_ipld_dagjson::codec::DagJsonCodec;\n\n#[derive(Deserialize, Serialize)]\nstruct Tree {\n    height: u8,\n    age: u8,\n}\n\nfn encode_generic\u003cC, T\u003e(value: \u0026T) -\u003e Result\u003cVec\u003cu8\u003e, C::Error\u003e\nwhere\n    C: Codec\u003cT\u003e,\n{\n    C::encode_to_vec(value)\n}\n\nfn main() {\n    let tree = Tree {\n        height: 12,\n        age: 91,\n    };\n\n    let cbor_encoded = encode_generic::\u003cDagCborCodec, _\u003e(\u0026tree);\n    #[allow(clippy::format_collect)]\n    let cbor_hex = cbor_encoded\n        .unwrap()\n        .iter()\n        .map(|byte| format!(\"{:02x}\", byte))\n        .collect::\u003cString\u003e();\n    // CBOR encoded: https://cbor.nemo157.com/#value=a2666865696768740c63616765185b\n    println!(\"CBOR encoded: https://cbor.nemo157.com/#value={}\", cbor_hex);\n    let json_encoded = encode_generic::\u003cDagJsonCodec, _\u003e(\u0026tree).unwrap();\n    // JSON encoded: {\"height\":12,\"age\":91}\n    println!(\"JSON encoded: {}\", str::from_utf8(\u0026json_encoded).unwrap());\n}\n```\n\n### Extracting links\n\nIf you are only interested in the links (CIDs) of an encoded IPLD object, then you can extract them them directly with [`Codec::links()`]:\n\n```rust\nuse ipld_core::{codec::{Codec, Links}, ipld, cid::Cid};\nuse serde_ipld_dagjson::codec::DagJsonCodec;\n\nfn main() {\n    let cid = Cid::try_from(\"bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy\").unwrap();\n    let data = ipld!({\"some\": {\"nested\": cid}, \"or\": [cid, cid], \"more\": true});\n\n    let mut encoded = Vec::new();\n    DagJsonCodec::encode(\u0026mut encoded, \u0026data).unwrap();\n\n    let links = DagJsonCodec::links(\u0026encoded).unwrap().collect::\u003cVec\u003c_\u003e\u003e();\n    // Extracted links: [Cid(bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy), Cid(bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy), Cid(bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy)]\n    println!(\"Extracted links: {:?}\", links);\n}\n```\n\n\nFeature flags\n-------------\n\n - `std` (enabled by default): Makes the error implement `std::error::Error` and the `Codec` trait available.\n - `codec` (enabled by default): Provides the `Codec` trait, which enables encoding and decoding independent of the IPLD Codec. The minimum supported Rust version (MSRV) can significantly be reduced to 1.64 by disabling this feature.\n - `serde`: Enables support for Serde serialization into/deserialization from the `Ipld` enum.\n - `arb`: Enables support for property based testing.\n\n\nLicense\n-------\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n[IPLD]: https://ipld.io/\n[libipld-core]: https://crates.io/crates/libipld-core\n[Serde]: https://serde.rs/\n[serde_ipld_dagcbor]: https://crates.io/crates/serde_ipld_dagcbor\n[serde_ipld_dagjson]: https://crates.io/crates/serde_ipld_dagjson\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipld%2Frust-ipld-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipld%2Frust-ipld-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipld%2Frust-ipld-core/lists"}