Spans
facet-pretty formats type shapes with syntax highlighting and span tracking. Use it to build rich error diagnostics that point to specific fields or variants in type definitions, integrating with miette for beautiful error reports.
Highlight Modes
Highlight Field Name
Point to the field name when it's unknown or unexpected.
Target Type
#[derive(Facet)]
struct Config {
name: String,
max_retries: u8,
timeout_ms: u32,
enabled: bool,
}
Error
× unknown field `max_retries`
╭─[target type:4:5]
3 │ name: String,
4 │ max_retries: u8,
· ─────┬─────
· ╰── not expected here
5 │ timeout_ms: u32,
╰────
Highlight Type
Point to the type when the value doesn't match.
Target Type
#[derive(Facet)]
struct Config {
name: String,
max_retries: u8,
timeout_ms: u32,
enabled: bool,
}
Error
× value 1000 is out of range for u8
╭─[target type:4:18]
3 │ name: String,
4 │ max_retries: u8,
· ─┬
· ╰── expected 0..255
5 │ timeout_ms: u32,
╰────
Highlight Entire Field
Point to both name and type for context.
Target Type
#[derive(Facet)]
struct Config {
name: String,
max_retries: u8,
timeout_ms: u32,
enabled: bool,
}
Error
× missing required field
╭─[target type:5:5]
4 │ max_retries: u8,
5 │ timeout_ms: u32,
· ───────┬───────
· ╰── this field is required
6 │ enabled: bool,
╰────
Nested Structures
Nested Struct Field
Highlight a field inside a nested struct.
Target Type
#[derive(Facet)]
struct Employee {
person: Person,
address: Address,
tags: Vec<String>,
metadata: HashMap<String, i32>,
}
#[derive(Facet)]
struct Address {
street: String,
city: String,
zip: String,
}
#[derive(Facet)]
struct Person {
name: String,
age: u8,
email: Option<String>,
}
Error
× invalid person data
╭─[target type:3:13]
2 │ struct Employee {
3 │ person: Person,
· ───┬──
· ╰── expected valid Person
4 │ address: Address,
╰────
Deeply Nested Field
Highlight a deeply nested field path.
Target Type
#[derive(Facet)]
struct Employee {
person: Person,
address: Address,
tags: Vec<String>,
metadata: HashMap<String, i32>,
}
#[derive(Facet)]
struct Address {
street: String,
city: String,
zip: String,
}
#[derive(Facet)]
struct Person {
name: String,
age: u8,
email: Option<String>,
}
Error
× address validation failed
╭─[target type:4:5]
3 │ person: Person,
4 │ address: Address,
· ────────┬───────
· ╰── city is required
5 │ tags: Vec<String>,
╰────
Enum Variants
Unit Variant
Highlight an enum variant name.
Target Type
#[derive(Facet)]
#[repr(u8)]
enum Status {
Active,
Pending,
Error {
code: i32,
message: String,
},
}
Error
× invalid variant
╭─[target type:4:5]
3 │ enum Status {
4 │ Active,
· ───┬──
· ╰── not allowed in this context
5 │ Pending,
╰────
Tuple Variant
Highlight a tuple variant.
Target Type
#[derive(Facet)]
#[repr(u8)]
enum Message {
Text(String),
Number(i32),
Pair(String, i32),
Data {
id: u64,
payload: Vec<u8>,
},
}
Error
× type mismatch
╭─[target type:4:10]
3 │ enum Message {
4 │ Text(String),
· ───┬───
· ╰── expected Number, got Text
5 │ Number(i32),
╰────
Struct Variant Field
Highlight a field inside a struct variant.
Target Type
#[derive(Facet)]
#[repr(u8)]
enum Status {
Active,
Pending,
Error {
code: i32,
message: String,
},
}
Error
× error code out of range
╭─[target type:7:15]
6 │ Error {
7 │ code: i32,
· ─┬─
· ╰── must be positive
8 │ message: String,
╰────
Collections
Vec Field
Highlight a Vec field type.
Target Type
#[derive(Facet)]
struct Employee {
person: Person,
address: Address,
tags: Vec<String>,
metadata: HashMap<String, i32>,
}
#[derive(Facet)]
struct Address {
street: String,
city: String,
zip: String,
}
#[derive(Facet)]
struct Person {
name: String,
age: u8,
email: Option<String>,
}
Error
× invalid tags
╭─[target type:5:11]
4 │ address: Address,
5 │ tags: Vec<String>,
· ─────┬─────
· ╰── expected array of strings
6 │ metadata: HashMap<String, i32>,
╰────
Option Field
Highlight an Option field.
Target Type
#[derive(Facet)]
struct Person {
name: String,
age: u8,
email: Option<String>,
}
Error
× invalid email format
╭─[target type:5:5]
4 │ age: u8,
5 │ email: Option<String>,
· ──────────┬──────────
· ╰── must be a valid email address
6 │ }
╰────
HashMap Field
Highlight a HashMap field.
Target Type
#[derive(Facet)]
struct Employee {
person: Person,
address: Address,
tags: Vec<String>,
metadata: HashMap<String, i32>,
}
#[derive(Facet)]
struct Address {
street: String,
city: String,
zip: String,
}
#[derive(Facet)]
struct Person {
name: String,
age: u8,
email: Option<String>,
}
Error
× invalid metadata
╭─[target type:6:15]
5 │ tags: Vec<String>,
6 │ metadata: HashMap<String, i32>,
· ──────────┬─────────
· ╰── keys must be alphanumeric
7 │ }
╰────