Remove Debug
constraint on SumTree
(and its related traits/structs) (#18248)
Release Notes: - N/A Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
3ba071b993
commit
d989183f94
4 changed files with 69 additions and 28 deletions
|
@ -34,7 +34,7 @@ pub trait KeyedItem: Item {
|
|||
///
|
||||
/// Each Summary type can have multiple [`Dimensions`] that it measures,
|
||||
/// which can be used to navigate the tree
|
||||
pub trait Summary: Clone + fmt::Debug {
|
||||
pub trait Summary: Clone {
|
||||
type Context;
|
||||
|
||||
fn zero(cx: &Self::Context) -> Self;
|
||||
|
@ -49,7 +49,7 @@ pub trait Summary: Clone + fmt::Debug {
|
|||
/// # Example:
|
||||
/// Zed's rope has a `TextSummary` type that summarizes lines, characters, and bytes.
|
||||
/// Each of these are different dimensions we may want to seek to
|
||||
pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug {
|
||||
pub trait Dimension<'a, S: Summary>: Clone {
|
||||
fn zero(cx: &S::Context) -> Self;
|
||||
|
||||
fn add_summary(&mut self, summary: &'a S, cx: &S::Context);
|
||||
|
@ -71,7 +71,7 @@ impl<'a, T: Summary> Dimension<'a, T> for T {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait SeekTarget<'a, S: Summary, D: Dimension<'a, S>>: fmt::Debug {
|
||||
pub trait SeekTarget<'a, S: Summary, D: Dimension<'a, S>> {
|
||||
fn cmp(&self, cursor_location: &D, cx: &S::Context) -> Ordering;
|
||||
}
|
||||
|
||||
|
@ -173,9 +173,19 @@ impl Bias {
|
|||
/// The maximum number of items per node is `TREE_BASE * 2`.
|
||||
///
|
||||
/// Any [`Dimension`] supported by the [`Summary`] type can be used to seek to a specific location in the tree.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct SumTree<T: Item>(Arc<Node<T>>);
|
||||
|
||||
impl<T> fmt::Debug for SumTree<T>
|
||||
where
|
||||
T: fmt::Debug + Item,
|
||||
T::Summary: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("SumTree").field(&self.0).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Item> SumTree<T> {
|
||||
pub fn new(cx: &<T::Summary as Summary>::Context) -> Self {
|
||||
SumTree(Arc::new(Node::Leaf {
|
||||
|
@ -763,7 +773,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone)]
|
||||
pub enum Node<T: Item> {
|
||||
Internal {
|
||||
height: u8,
|
||||
|
@ -778,6 +788,39 @@ pub enum Node<T: Item> {
|
|||
},
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Node<T>
|
||||
where
|
||||
T: Item + fmt::Debug,
|
||||
T::Summary: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Node::Internal {
|
||||
height,
|
||||
summary,
|
||||
child_summaries,
|
||||
child_trees,
|
||||
} => f
|
||||
.debug_struct("Internal")
|
||||
.field("height", height)
|
||||
.field("summary", summary)
|
||||
.field("child_summaries", child_summaries)
|
||||
.field("child_trees", child_trees)
|
||||
.finish(),
|
||||
Node::Leaf {
|
||||
summary,
|
||||
items,
|
||||
item_summaries,
|
||||
} => f
|
||||
.debug_struct("Leaf")
|
||||
.field("summary", summary)
|
||||
.field("items", items)
|
||||
.field("item_summaries", item_summaries)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Item> Node<T> {
|
||||
fn is_leaf(&self) -> bool {
|
||||
matches!(self, Node::Leaf { .. })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue