liminal-rs 0.11.0

A conversation-based messaging bus built on beamr
Documentation
//! `Frame`'s `Debug`, written by hand (ACCESS-004 R5).
//!
//! A `Connect` carries a credential, a bearer token or a whole registry
//! pass, so its `Debug` names `auth_token` by its length only. Every other
//! variant prints exactly what the derived `Debug` printed: its name and
//! each field, in declaration order, listed once below.

use core::fmt;

use super::Frame;

/// A credential field: its length, never its bytes.
struct ByteLength(usize);

impl fmt::Debug for ByteLength {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(formatter, "{} bytes", self.0)
    }
}

macro_rules! frame_debug {
    ($($variant:ident { $($field:ident),* }),* $(,)?) => {
        impl fmt::Debug for Frame {
            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                match self {
                    Self::Connect {
                        flags,
                        min_version,
                        max_version,
                        auth_token,
                    } => formatter
                        .debug_struct("Connect")
                        .field("flags", flags)
                        .field("min_version", min_version)
                        .field("max_version", max_version)
                        .field("auth_token", &ByteLength(auth_token.len()))
                        .finish(),
                    $(Self::$variant { $($field),* } => {
                        let mut out = formatter.debug_struct(stringify!($variant));
                        $(out.field(stringify!($field), $field);)*
                        out.finish()
                    })*
                }
            }
        }
    };
}

frame_debug! {
    ConnectAck { flags, selected_version, capabilities },
    ConnectError { flags, reason_code, message },
    Disconnect { flags },
    Subscribe { flags, stream_id, channel, accepted_schemas, max_in_flight },
    SubscribeAck { flags, stream_id, subscription_id, selected_schema },
    SubscribeError { flags, stream_id, reason_code, message },
    Unsubscribe { flags, stream_id, subscription_id },
    Publish { flags, stream_id, channel, envelope, idempotency_key },
    PublishAck { flags, stream_id, message_id, durable_position },
    PublishError { flags, stream_id, reason_code, message },
    ConversationOpen { flags, stream_id, conversation_id, subject },
    ConversationMessage { flags, stream_id, conversation_id, envelope },
    ConversationClose { flags, stream_id, conversation_id, reason_code, message },
    ConversationError { flags, stream_id, conversation_id, reason_code, message },
    Accept { flags, stream_id, referenced_message_id },
    Defer { flags, stream_id, referenced_message_id, reason },
    Reject { flags, stream_id, referenced_message_id, reason },
    Ping { flags },
    Pong { flags },
    Push { flags, stream_id, correlation_id, payload },
    PushReply { flags, stream_id, correlation_id, payload },
    WorkerRegister { flags, registration },
    WorkerRegisterAck { flags, outcome },
    Deliver { flags, stream_id, delivery_seq, envelope, message },
    Unknown { type_id, flags, stream_id, payload },
}