pub enum Ipld {
Null,
Bool(bool),
Integer(i128),
Float(f64),
String(String),
Bytes(Vec<u8>),
List(Vec<Ipld>),
Map(BTreeMap<String, Ipld>),
Link(SerializableCid),
}Expand description
IPLD data model
Represents the core IPLD data types that can be stored and transferred across the IPFRS network.
Variants§
Null
Null value
Bool(bool)
Boolean value
Integer(i128)
Integer value (supports full i128 range)
Float(f64)
Float value (IEEE 754 double precision)
String(String)
String value (UTF-8)
Bytes(Vec<u8>)
Bytes value (raw binary data)
List(Vec<Ipld>)
List of IPLD values
Map(BTreeMap<String, Ipld>)
Map of string keys to IPLD values (keys are sorted)
Link(SerializableCid)
Link to another IPLD node via CID
Implementations§
Source§impl Ipld
impl Ipld
Sourcepub fn to_dag_cbor(&self) -> Result<Vec<u8>>
pub fn to_dag_cbor(&self) -> Result<Vec<u8>>
Encode this IPLD value to DAG-CBOR format
DAG-CBOR is a deterministic subset of CBOR with:
- Map keys sorted by byte ordering
- No indefinite-length items
- CID links encoded with tag 42
Sourcepub fn from_dag_cbor(data: &[u8]) -> Result<Self>
pub fn from_dag_cbor(data: &[u8]) -> Result<Self>
Decode IPLD value from DAG-CBOR format
Sourcepub fn to_dag_json(&self) -> Result<String>
pub fn to_dag_json(&self) -> Result<String>
Encode this IPLD value to DAG-JSON format
DAG-JSON is a JSON encoding for IPLD with special handling for:
- Bytes (encoded as
{"/": {"bytes": "<base64>"}}) - Links (encoded as
{"/": "<cid-string>"})
Sourcepub fn from_dag_json(json: &str) -> Result<Self>
pub fn from_dag_json(json: &str) -> Result<Self>
Decode IPLD value from DAG-JSON format
Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
Encode this IPLD value to JSON format (simple, for debugging)
Sourcepub fn links(&self) -> Vec<Cid> ⓘ
pub fn links(&self) -> Vec<Cid> ⓘ
Get all CID links contained in this IPLD structure (recursively)
Sourcepub const fn is_integer(&self) -> bool
pub const fn is_integer(&self) -> bool
Check if this is an integer value
Sourcepub const fn as_integer(&self) -> Option<i128>
pub const fn as_integer(&self) -> Option<i128>
Extract integer value if this is an Integer
Sourcepub fn index(&self, idx: usize) -> Option<&Ipld>
pub fn index(&self, idx: usize) -> Option<&Ipld>
Get a value from a list by index (if this is a List)
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the size/length of this IPLD value
- For List: number of elements
- For Map: number of key-value pairs
- For String: length in bytes
- For Bytes: length in bytes
- For other types: 0
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Ipld
impl<'de> Deserialize<'de> for Ipld
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl StructuralPartialEq for Ipld
Auto Trait Implementations§
impl Freeze for Ipld
impl RefUnwindSafe for Ipld
impl Send for Ipld
impl Sync for Ipld
impl Unpin for Ipld
impl UnwindSafe for Ipld
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more