std::serializer::error
Serializer Errors
Shared structured error types for std serialization entrypoints.
Overview
Serializer errors are format-neutral. Front-ends such as std::json and
std::toml return the same error type so callers can handle serialization
failures without depending on a concrete writer implementation.
Error Kinds
| Kind | Meaning |
|---|---|
UNSUPPORTED_ROOT_SHAPE |
The format rejected the requested root value |
INVALID_FIELD_KEY |
A record field key cannot be emitted safely |
Error messages are human-readable diagnostics. Match on kind for program
control flow.
namespace SerializerRecords
record ErrorStructured serializer failure with a stable kind and diagnostic message.
kind: ErrorKindMachine-readable error category.
message: StringHuman-readable explanation suitable for diagnostics.
static invalidFieldKey(message: str): ErrorCreates an INVALID_FIELD_KEY error.
Used when a writer requires bare keys and the supplied field name does not match the serializer’s accepted bare-key character set.
Example
let error: Serializer::Error = Serializer::Error::invalidFieldKey(
"bare field keys only support ASCII letters, digits, '_' and '-'",
);
static new(kind: ErrorKind, message: str): ErrorCreates a serializer error with an owned diagnostic message.
Arguments
kind: stable category used by callers for control flow.message: human-readable explanation copied into the error.
Example
let error: Serializer::Error = Serializer::Error::new(
Serializer::ErrorKind::INVALID_FIELD_KEY,
"field key must be bare ASCII",
);
static unsupportedRootShape(message: str): ErrorCreates an UNSUPPORTED_ROOT_SHAPE error.
Used when a front-end such as TOML rejects scalar document roots.
Example
let error: Serializer::Error = Serializer::Error::unsupportedRootShape(
"TOML root must be a record",
);
Enums
enum ErrorKindMachine-readable serializer failure category.
UNSUPPORTED_ROOT_SHAPEINVALID_FIELD_KEY