Crates.io | ipld-extract-links |
lib.rs | ipld-extract-links |
version | 0.1.0 |
source | src |
created_at | 2024-03-08 00:31:33.020353 |
updated_at | 2024-03-08 00:31:33.020353 |
description | Extract links from IPLD encoded data |
homepage | |
repository | https://github.com/ipld/rust-ipld-extract-links |
max_upload_size | |
id | 1166396 |
size | 18,905 |
This crate allow extracting links (CIDs) from serde_ipld_dag*
formats like serde_ipld_dagcbor
or serde_ipld_dagjson
.
The link extractor is independent of the deserializer, hence you need to create one first. Therefore this example depends on serde_json
as well as serde_ipld_dagjson
.
use cid::Cid;
use ipld_extract_links::ExtractLinks;
use serde::Deserialize;
pub fn main() {
let slice = br#"{"hello": "world!", "other": {"/": "bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy" }}"#;
let mut json_deserializer = serde_json::Deserializer::from_slice(slice);
let deserializer = serde_ipld_dagjson::Deserializer::new(&mut json_deserializer);
let extracted_links = ExtractLinks::deserialize(deserializer).unwrap().into_vec();
assert_eq!(
extracted_links,
vec![
Cid::try_from("bafkreibme22gw2h7y2h7tg2fhqotaqjucnbc24deqo72b6mkl2egezxhvy").unwrap(),
]
);
}
Licensed under either of
at your option.