From 582557d79f660ae0bc317c45ef2e5cdc2b72fca9 Mon Sep 17 00:00:00 2001 From: Kirpal Grewal Date: Wed, 20 Nov 2024 12:44:19 +0000 Subject: [PATCH] add debug impls --- tree_arena/src/tree_arena_safe.rs | 12 ++++++++---- tree_arena/src/tree_arena_unsafe.rs | 11 +++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tree_arena/src/tree_arena_safe.rs b/tree_arena/src/tree_arena_safe.rs index c55d74e88..650454d48 100644 --- a/tree_arena/src/tree_arena_safe.rs +++ b/tree_arena/src/tree_arena_safe.rs @@ -11,12 +11,11 @@ //! will use an arena and unsafe code, but should have the exact same exported API as //! this module. -#![expect(missing_debug_implementations, reason = "Deferred: Noisy")] - use super::NodeId; use std::collections::HashMap; +#[derive(Debug)] struct TreeNode { id: NodeId, item: T, @@ -32,7 +31,7 @@ struct TreeNode { /// will keep track of parent-child relationships, lets you efficiently find /// an item anywhere in the tree hierarchy, and give you mutable access to this item /// and its children. -#[derive(Default)] +#[derive(Debug, Default)] pub struct TreeArena { roots: Vec>, parents_map: HashMap>, @@ -42,6 +41,7 @@ pub struct TreeArena { /// /// When you borrow an item from a [`TreeArena`], it returns an `ArenaRef`. /// You can iterate over its children to get access to child `ArenaRef` handles. +#[derive(Debug)] pub struct ArenaRef<'arena, T> { /// The parent of this node pub parent_id: Option, @@ -63,6 +63,7 @@ pub struct ArenaRef<'arena, T> { /// and its children independently without invalidating the references. /// /// You can iterate over its children to get access to child `ArenaMut` handles. +#[derive(Debug)] pub struct ArenaMut<'arena, T> { /// The parent of the node pub parent_id: Option, @@ -75,6 +76,7 @@ pub struct ArenaMut<'arena, T> { /// A handle giving shared access to an arena item's children. /// /// See [`ArenaRef`] for more information. +#[derive(Debug)] pub struct ArenaRefChildren<'arena, T> { id: Option, children: &'arena Vec>, @@ -84,6 +86,7 @@ pub struct ArenaRefChildren<'arena, T> { /// A handle giving mutable access to an arena item's children. /// /// See [`ArenaMut`] for more information. +#[derive(Debug)] pub struct ArenaMutChildren<'arena, T> { id: Option, children: &'arena mut Vec>, @@ -91,12 +94,13 @@ pub struct ArenaMutChildren<'arena, T> { } /// A shared reference to the parent father map -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct ArenaMapRef<'arena> { parents_map: &'arena HashMap>, } /// A mutable reference to the parent father map +#[derive(Debug)] pub struct ArenaMapMut<'arena> { parents_map: &'arena mut HashMap>, } diff --git a/tree_arena/src/tree_arena_unsafe.rs b/tree_arena/src/tree_arena_unsafe.rs index 6a66751e5..47cefa9c8 100644 --- a/tree_arena/src/tree_arena_unsafe.rs +++ b/tree_arena/src/tree_arena_unsafe.rs @@ -1,19 +1,20 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -#![expect(missing_debug_implementations, reason = "Deferred: Noisy")] #![allow(unsafe_code, reason = "Purpose is unsafe abstraction")] use super::NodeId; use std::cell::UnsafeCell; use std::collections::HashMap; +#[derive(Debug)] struct TreeNode { item: T, children: Vec, } /// Mapping of data for the Tree Arena +#[derive(Debug)] struct DataMap { /// The items in the tree items: HashMap>>>, @@ -29,6 +30,7 @@ struct DataMap { /// will keep track of parent-child relationships, lets you efficiently find /// an item anywhere in the tree hierarchy, and give you mutable access to this item /// and its children. +#[derive(Debug)] pub struct TreeArena { /// The items in the tree data_map: DataMap, @@ -38,7 +40,7 @@ pub struct TreeArena { /// /// When you borrow an item from a [`TreeArena`], it returns an [`ArenaRef`]. /// You can access it children to get access to child [`ArenaRef`] handles. - +#[derive(Debug)] pub struct ArenaRef<'arena, T> { /// Parent of the Node pub parent_id: Option, @@ -51,6 +53,7 @@ pub struct ArenaRef<'arena, T> { /// A handle giving shared access to an arena item's children. /// /// See [`ArenaRef`] for more information. +#[derive(Debug)] pub struct ArenaRefChildren<'arena, T> { /// The associated data arena parent_arena: &'arena DataMap, @@ -74,7 +77,9 @@ impl Clone for ArenaRefChildren<'_, T> { *self } } + impl Copy for ArenaRefChildren<'_, Item> {} + /// A reference type giving mutable access to an arena item and its children. /// /// When you borrow an item from a [`TreeArena`], it returns an `ArenaMut`. @@ -87,6 +92,7 @@ impl Copy for ArenaRefChildren<'_, Item> {} /// and its children independently without invalidating the references. /// /// You can iterate over its children to get access to child `ArenaMut` handles. +#[derive(Debug)] pub struct ArenaMut<'arena, T> { /// Parent of the Node pub parent_id: Option, @@ -104,6 +110,7 @@ pub struct ArenaMut<'arena, T> { /// As such if a [`std::mem::swap`] is used to swap the children of two trees, /// each tree will still have the correct permissions. This also stores the roots, and so /// that will also be in a consistent state +#[derive(Debug)] pub struct ArenaMutChildren<'arena, T> { /// The associated data arena parent_arena: &'arena mut DataMap,