Skip to main content

codec_io_error

Function codec_io_error 

Source
pub fn codec_io_error(context: &str, err: CodecError) -> Error
Expand description

Map a CodecError to an io::Error, tagging the message with context so the failing boundary is identifiable.

A CodecError::Version mismatch becomes io::ErrorKind::InvalidData: a foreign on-disk/wire format is a structured, distinguishable condition — a caller can react to “this record is from another schema version” specifically rather than treating it as a generic decode failure. Every other variant maps through io::Error::other.

Consumers whose trait surface speaks io::Error — the openraft RaftLogStorage / RaftStateMachine implementations — share this one mapping so the version-mismatch-to-InvalidData contract can’t drift between them. (The paxos toolkit surfaces CodecError through its own thiserror error enum and so does not use this.)