StatefulCoder

public protocol StatefulCoder

An object that flattens values into—or reconstitutes values from—a serialized Encoding, maintaining state across the (de)serialization of individual parts.

Note

this protocol matches Foundation’s XXXEncoder/XXXDecoder types, which—confusingly—do not themselves conform to the Encoder/Decoder protocols.
  • The complete result of serializing anything with self.

    Declaration

    Swift

    associatedtype Encoding = Data
  • The storage vehicle for state.

    Declaration

    Swift

    var userInfo: [CodingUserInfoKey : any Sendable] { get set }
  • setState(_:) Extension method

    Injects initialState into self for use as mutable storage during encoding/decoding.

    Declaration

    Swift

    public mutating func setState<T>(_ initialState: T) where T : Sendable