tracel-ai/burn · error
deserialize_unit_struct is not implemented
Error message
deserialize_unit_struct is not implemented
What it means
The nested-value deserializer panics on `deserialize_unit_struct` because unit-like structs (e.g., `struct Marker;`) have no NestedValue representation. Any record type referencing such a struct hits this deliberate unimplemented!() during deserialization.
Source
Thrown at crates/burn-store/src/nested/de.rs:312
}
}
fn deserialize_unit<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
unimplemented!("deserialize_unit is not implemented")
}
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
_visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
unimplemented!("deserialize_unit_struct is not implemented")
}
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
let value = self
.value
.ok_or_else(|| custom_err("expected value for newtype struct but got None"))?;
visitor.visit_newtype_struct(Deserializer::<A>::new(
value,
self.default_for_missing_fields,
))
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Replace the unit-struct field with an empty struct that implements Deserialize via a zero-field struct (deserialize_struct with empty fields) or remove it entirely.
- Use PhantomData instead of a unit struct for type markers.
- Regenerate the checkpoint to match the supported record schema.
- Add #[serde(skip)] semantics by restructuring the type so the marker is not part of the serialized data.
Example fix
// before
struct Marker;
struct Item { m: Marker } // -> deserialize_unit_struct panic
// after
struct Item { _m: core::marker::PhantomData<Marker> } // not serialized Defensive patterns
Strategy: validation
Validate before calling
// Replace unit structs with PhantomData markers:
// struct Marker;
// struct Item { _m: PhantomData<Marker> } // not part of serialized data Try / catch
let record = std::panic::catch_unwind(|| from_nested_value::<MyItem>(value.clone()))
.map_err(|_| "record contains unit struct: not supported by nested deserializer"); Prevention
- Avoid unit structs as fields in serializable record types.
- Use PhantomData for type-state markers.
- Round-trip test records after introducing new marker types.
When it happens
Trigger: Deserializing a Burn record that includes a field whose type is a unit struct (a braced-less struct with no fields), causing serde to call Deserializer::deserialize_unit_struct.
Common situations: Marker types used in module/record definitions (e.g., type-state markers); schema refactors that introduced marker fields; version drift between the code that saved the checkpoint and the code loading it.
Related errors
- deserialize_any is not implemented
- deserialize_i8 is not implemented
- deserialize_u32 is not implemented
- deserialize_char is not implemented
- deserialize_bytes is not implemented
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/769f29b2798dac8a.
Report an issue: GitHub.