Module

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 Serializer

Records

record Error

Structured serializer failure with a stable kind and diagnostic message.

Members
kind: ErrorKind

Machine-readable error category.

message: String

Human-readable explanation suitable for diagnostics.

static invalidFieldKey(message: str): Error

Creates 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): Error

Creates 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): Error

Creates 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 ErrorKind

Machine-readable serializer failure category.

Members
UNSUPPORTED_ROOT_SHAPE
INVALID_FIELD_KEY