Assertions

facet-assert provides structural assertions for any Facet type without requiring PartialEq or Debug. Compare values across different types with identical structure, and get precise structural diffs showing exactly which fields differ.

Same Values

Two values with identical content pass assert_same! — no PartialEq required.

Target Type
#[derive(Facet)]
struct Config {
    host: String,
<span style="color:#7aa2f7;">port</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">u16</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">debug</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">bool</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">tags</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Vec</span><span style="color:#a9b1d6;">&lt;</span><span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">&gt;,</span>

}

Success

Config {
  host"localhost",
  port8080,
  debugtrue,
  tagsVec<String> ["prod", "api"],
}

Cross-Type Comparison

Different type names (Config vs ConfigV2) with the same structure are considered "same". Useful for comparing DTOs across API versions or testing serialization roundtrips.

Target Type
#[derive(Facet)]
struct Config {
    host: String,
<span style="color:#7aa2f7;">port</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">u16</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">debug</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">bool</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">tags</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Vec</span><span style="color:#a9b1d6;">&lt;</span><span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">&gt;,</span>

}

Success

Config {
  host"localhost",
  port8080,
  debugtrue,
  tagsVec<String> ["prod"],
}

Nested Structs

Nested structs are compared recursively, field by field.

Target Type
#[derive(Facet)]
struct Person {
    name: String,
<span style="color:#7aa2f7;">age</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">u32</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">address</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Address</span><span style="color:#a9b1d6;">,</span>

}

#[derive(Facet)] struct Address { street: String,

<span style="color:#7aa2f7;">city</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">,</span>

}

Success

Person {
  name"Alice",
  age30,
  addressAddress {
    street"123 Main St",
    city"Springfield",
  },
}

Structural Diff

When values differ, you get a precise structural diff showing exactly which fields changed and at what path — then render it as Rust, JSON, or XML for whichever toolchain you need.

Rust Diff Output

{
    debug: true → false
    host: "localhost" → "prod.example.com"
    port: 8080 → 443
    tags: [
        .. 1 unchanged item
        - "api"
    ]
}

JSON Diff Output

    { /* Config */
       "debug": true , "host": "localhost"       , "port": 8080
       "debug": false"host": "prod.example.com""port": 443
    
        "tags": [],
    }

XML Diff Output

    <Config
       debug="true"  host="localhost"        port="8080"
       debug="false" host="prod.example.com" port="443"
    >
        <tags></tags>
    </Config>

Vector Differences

Vector comparisons show exactly which indices differ, which elements were added, and which were removed.

Diff Output

[
    .. 2 unchanged items
    3 → 99
    .. 1 unchanged item
    - 5
]