Structural CBOR value equality, the reference's PartialEq for CBOR
(cbor.rs): two values are equal when they have the same major type and
equal contents, compared recursively.
This is not "encode to the same bytes": a float node whose value is whole
(Float(2.0), reachable through a bare node) encodes as the integer 2
but is not equal to the integer node; a text node keeps the string it was
built from, so a decomposed "é" is not equal to the composed one although
both encode composed. Integers compare by value across number/bigint;
tags compare by value only (the carried name is ignored); NaN equals NaN;
maps compare entry by entry in canonical key order, keys and values both
structurally.
Use this rather than === (which compares JS object references) when
you need value equality across two Cbor instances built independently.
Structural CBOR value equality, the reference's
PartialEq for CBOR(cbor.rs): two values are equal when they have the same major type and equal contents, compared recursively.This is not "encode to the same bytes": a float node whose value is whole (
Float(2.0), reachable through a bare node) encodes as the integer2but is not equal to the integer node; a text node keeps the string it was built from, so a decomposed"é"is not equal to the composed one although both encode composed. Integers compare by value acrossnumber/bigint; tags compare by value only (the carried name is ignored); NaN equals NaN; maps compare entry by entry in canonical key order, keys and values both structurally.Use this rather than
===(which compares JS object references) when you need value equality across twoCborinstances built independently.