atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git

Blame: crates/matrix-sdk-base/src/debug.rs

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
// Copyright 2023 The Matrix.org Foundation C.I.C.
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
// Licensed under the Apache License, Version 2.0 (the "License");
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
// you may not use this file except in compliance with the License.
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
// You may obtain a copy of the License at
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
//     http://www.apache.org/licenses/LICENSE-2.0
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
// Unless required by applicable law or agreed to in writing, software
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
// distributed under the License is distributed on an "AS IS" BASIS,
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
// See the License for the specific language governing permissions and
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
// limitations under the License.
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
//! Helpers for creating `std::fmt::Debug` implementations.
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
use std::fmt;
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
pub use matrix_sdk_common::debug::*;
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent;
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
use ruma::{
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
    api::client::sync::sync_events::v3::{InvitedRoom, KnockedRoom},
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
    serde::Raw,
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
};
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
/// A wrapper around a slice of `Raw` events that implements `Debug` in a way
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
/// that only prints the event type of each item.
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
pub struct DebugListOfRawEventsNoId<'a, T>(pub &'a [Raw<T>]);
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
#[cfg(not(tarpaulin_include))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
impl<T> fmt::Debug for DebugListOfRawEventsNoId<'_, T> {
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
        let mut list = f.debug_list();
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
        list.entries(self.0.iter().map(DebugRawEventNoId));
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
        list.finish()
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
    }
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
}
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
/// A wrapper around a slice of `ProcessedToDeviceEvent` events that implements
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
/// `Debug` in a way that only prints the event type of each item.
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
pub struct DebugListOfProcessedToDeviceEvents<'a>(pub &'a [ProcessedToDeviceEvent]);
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
#[cfg(not(tarpaulin_include))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
impl fmt::Debug for DebugListOfProcessedToDeviceEvents<'_> {
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
        let mut list = f.debug_list();
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
        list.entries(self.0.iter().map(|e| DebugRawEventNoId(e.as_raw())));
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
        list.finish()
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
    }
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
}
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
/// A wrapper around an invited room as found in `/sync` responses that
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
/// implements `Debug` in a way that only prints the event ID and event type for
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
/// the raw events contained in `invite_state`.
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
pub struct DebugInvitedRoom<'a>(pub &'a InvitedRoom);
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
#[cfg(not(tarpaulin_include))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
impl fmt::Debug for DebugInvitedRoom<'_> {
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
        f.debug_struct("InvitedRoom")
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
            .field("invite_state", &DebugListOfRawEvents(&self.0.invite_state.events))
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
            .finish()
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
    }
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
}
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
/// A wrapper around a knocked on room as found in `/sync` responses that
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
/// implements `Debug` in a way that only prints the event ID and event type for
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
/// the raw events contained in `knock_state`.
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
pub struct DebugKnockedRoom<'a>(pub &'a KnockedRoom);
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
#[cfg(not(tarpaulin_include))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
impl fmt::Debug for DebugKnockedRoom<'_> {
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
        f.debug_struct("KnockedRoom")
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
            .field("knock_state", &DebugListOfRawEvents(&self.0.knock_state.events))
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
            .finish()
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
    }
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
}
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
7ff8adafe9e4atagen2026-10-22 12:30 UTC80
pub(crate) struct DebugListOfRawEvents<'a, T>(pub &'a [Raw<T>]);
7ff8adafe9e4atagen2026-10-22 12:30 UTC81
7ff8adafe9e4atagen2026-10-22 12:30 UTC82
#[cfg(not(tarpaulin_include))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC83
impl<T> fmt::Debug for DebugListOfRawEvents<'_, T> {
7ff8adafe9e4atagen2026-10-22 12:30 UTC84
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7ff8adafe9e4atagen2026-10-22 12:30 UTC85
        let mut list = f.debug_list();
7ff8adafe9e4atagen2026-10-22 12:30 UTC86
        list.entries(self.0.iter().map(DebugRawEvent));
7ff8adafe9e4atagen2026-10-22 12:30 UTC87
        list.finish()
7ff8adafe9e4atagen2026-10-22 12:30 UTC88
    }
7ff8adafe9e4atagen2026-10-22 12:30 UTC89
}