Helia JSON
JSON support for Helia, providing simple JSON serialization and storage for structured data compatible with IPFS JSON specification.
Example
use create_helia;
use ;
use ;
use HashMap;
use Arc;
async
JSON support for Helia, providing simple JSON serialization and storage for structured data compatible with IPFS JSON specification.
use helia::create_helia;
use helia_json::{Json, JsonInterface};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct MyData {
hello: String,
numbers: Vec<i32>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let helia = create_helia(None).await?;
let json = Json::new(Arc::new(helia));
let data = MyData {
hello: "world".to_string(),
numbers: vec![1, 2, 3],
};
// Add JSON data
let cid = json.add(&data, None).await?;
// Retrieve JSON data
let retrieved: MyData = json.get(&cid, None).await?;
assert_eq!(data, retrieved);
Ok(())
}