7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2023 The Matrix.org Foundation C.I.C. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for the specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | //! Helpers for creating `std::fmt::Debug` implementations. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | use std::fmt; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | pub use matrix_sdk_common::debug::*; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | api::client::sync::sync_events::v3::{InvitedRoom, KnockedRoom}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | serde::Raw, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | /// A wrapper around a slice of `Raw` events that implements `Debug` in a way |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | /// that only prints the event type of each item. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | pub struct DebugListOfRawEventsNoId<'a, T>(pub &'a [Raw<T>]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | #[cfg(not(tarpaulin_include))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | impl<T> fmt::Debug for DebugListOfRawEventsNoId<'_, T> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | let mut list = f.debug_list(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | list.entries(self.0.iter().map(DebugRawEventNoId)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | list.finish() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | /// A wrapper around a slice of `ProcessedToDeviceEvent` events that implements |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | /// `Debug` in a way that only prints the event type of each item. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | pub struct DebugListOfProcessedToDeviceEvents<'a>(pub &'a [ProcessedToDeviceEvent]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | #[cfg(not(tarpaulin_include))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | impl fmt::Debug for DebugListOfProcessedToDeviceEvents<'_> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | let mut list = f.debug_list(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | list.entries(self.0.iter().map(|e| DebugRawEventNoId(e.as_raw()))); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | list.finish() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | /// A wrapper around an invited room as found in `/sync` responses that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | /// implements `Debug` in a way that only prints the event ID and event type for |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | /// the raw events contained in `invite_state`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | pub struct DebugInvitedRoom<'a>(pub &'a InvitedRoom); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | #[cfg(not(tarpaulin_include))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | impl fmt::Debug for DebugInvitedRoom<'_> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | f.debug_struct("InvitedRoom") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | .field("invite_state", &DebugListOfRawEvents(&self.0.invite_state.events)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | .finish() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | /// A wrapper around a knocked on room as found in `/sync` responses that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | /// implements `Debug` in a way that only prints the event ID and event type for |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | /// the raw events contained in `knock_state`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | pub struct DebugKnockedRoom<'a>(pub &'a KnockedRoom); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | #[cfg(not(tarpaulin_include))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | impl fmt::Debug for DebugKnockedRoom<'_> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | f.debug_struct("KnockedRoom") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | .field("knock_state", &DebugListOfRawEvents(&self.0.knock_state.events)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | .finish() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | pub(crate) struct DebugListOfRawEvents<'a, T>(pub &'a [Raw<T>]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | #[cfg(not(tarpaulin_include))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | impl<T> fmt::Debug for DebugListOfRawEvents<'_, T> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | let mut list = f.debug_list(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | list.entries(self.0.iter().map(DebugRawEvent)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | list.finish() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | } |