Ipld

Enum Ipld 

Source
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 to another IPLD node via CID

Implementations§

Source§

impl Ipld

Create a link to a CID

Check if this is a link

Extract CID if this is a link

Source

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
Source

pub fn from_dag_cbor(data: &[u8]) -> Result<Self>

Decode IPLD value from DAG-CBOR format

Source

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>"})
Source

pub fn from_dag_json(json: &str) -> Result<Self>

Decode IPLD value from DAG-JSON format

Source

pub fn to_json(&self) -> Result<String>

Encode this IPLD value to JSON format (simple, for debugging)

Source

pub fn from_json(json: &str) -> Result<Self>

Decode IPLD value from JSON format

Get all CID links contained in this IPLD structure (recursively)

Source

pub const fn is_null(&self) -> bool

Check if this is a null value

Source

pub const fn is_bool(&self) -> bool

Check if this is a boolean value

Source

pub const fn is_integer(&self) -> bool

Check if this is an integer value

Source

pub const fn is_float(&self) -> bool

Check if this is a float value

Source

pub const fn is_string(&self) -> bool

Check if this is a string value

Source

pub const fn is_bytes(&self) -> bool

Check if this is a bytes value

Source

pub const fn is_list(&self) -> bool

Check if this is a list value

Source

pub const fn is_map(&self) -> bool

Check if this is a map value

Source

pub const fn as_bool(&self) -> Option<bool>

Extract boolean value if this is a Bool

Source

pub const fn as_integer(&self) -> Option<i128>

Extract integer value if this is an Integer

Source

pub const fn as_float(&self) -> Option<f64>

Extract float value if this is a Float

Source

pub fn as_string(&self) -> Option<&str>

Extract string reference if this is a String

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Extract bytes reference if this is Bytes

Source

pub fn as_list(&self) -> Option<&[Ipld]>

Extract list reference if this is a List

Source

pub fn as_map(&self) -> Option<&BTreeMap<String, Ipld>>

Extract map reference if this is a Map

Source

pub fn get(&self, key: &str) -> Option<&Ipld>

Get a value from a map by key (if this is a Map)

Source

pub fn index(&self, idx: usize) -> Option<&Ipld>

Get a value from a list by index (if this is a List)

Source

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
Source

pub fn is_empty(&self) -> bool

Check if this IPLD value is empty

  • For List/Map/String/Bytes: checks if length is 0
  • For Null: true
  • For other types: false
Source

pub const fn type_name(&self) -> &'static str

Get a human-readable type name for this IPLD value

Trait Implementations§

Source§

impl Clone for Ipld

Source§

fn clone(&self) -> Ipld

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ipld

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Ipld

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for Ipld

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Cid<64>> for Ipld

Source§

fn from(cid: Cid) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Ipld

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Ipld

Source§

fn from(bytes: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Ipld

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Ipld

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Ipld

Source§

fn from(i: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Ipld

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Ipld

Source§

fn from(u: u64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Ipld

Source§

fn eq(&self, other: &Ipld) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ipld

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,