#[derive(TestVectorSet)]
{
// Attributes available to this derive:
#[test_vec]
}
Expand description
Derive macro for [assert_tv::TestVectorSet].
This macro generates an implementation of
impl assert_tv::TestVectorSet for YourStruct { … }whose start::<TV>() constructor populates each field with an
[assert_tv::TestValue<T>] pre‑initialised for the current source‑code
location.
§Requirements
- All struct fields must be of type
TestValue<…>. - The struct must be non‑tuple, non‑unit, with named fields.
§Field attributes
Each field may carry zero or more #[test_vec(...)] helpers:
| Key | Type | Meaning | Default if omitted |
|---|---|---|---|
name | &'static str | Human‑readable display name. | None |
description | &'static str | Longer explanation for docs / reports. | None |
serialize_with | path to fn(&T) -> anyhow::Result<serde_json::Value> | Custom serializer | serde_json::to_value |
deserialize_with | path to fn(&serde_json::Value) -> anyhow::Result<T> | Custom deserializer | serde_json::from_value |
Multiple #[test_vec] attributes may be stacked on the same field:
ⓘ
#[test_vec(name = "counter")]
#[test_vec(description = "u64 monotonically increasing")]
#[test_vec(serialize_with = "my_serialize")]
count: TestValue<u64>,Duplicate keys on the same field are rejected with a clear error
(duplicate "name" key, etc.).
§Example
ⓘ
use assert_tv::{TestVectorSet, TestValue};
#[derive(TestVectorSet)]
struct SomeTestFields {
#[test_vec(name = "a", description = "a is a u64")]
#[test_vec(serialize_with = "custom_serialize_fn")]
#[test_vec(deserialize_with = "custom_deserialize_fn")]
a: TestValue<u64>,
// No attributes: falls back to defaults.
b: TestValue<String>,
}
fn custom_serialize_fn(v: &u64) -> anyhow::Result<serde_json::Value> {
Ok(serde_json::json!(v))
}
fn custom_deserialize_fn(v: &serde_json::Value) -> anyhow::Result<u64> {
Ok(v.as_u64().unwrap_or_default())
}Running cargo doc --open after adding this comment will render the
table, example, and key descriptions in a readable, searchable format.