sum_tree: Do not implement Dimension on tuples, use new Dimensions wrapper instead (#35482)

This is a bit of a readability improvement IMHO; I often find myself
confused when dealing when dimension pairs, as there's no easy way to
jump to the implementation of a dimension for tuples to remind myself
for the n-th time how exactly that impl works. Now it should be possible
to jump directly to that impl.

Another bonus is that Dimension supports 3-ary tuples as well - by using
a () as a default value of a 3rd dimension.


Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-05 02:37:22 +02:00 committed by GitHub
parent be2f54b233
commit 07e3d53d58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 215 additions and 141 deletions

View file

@ -13,7 +13,7 @@ use std::{
ops::{ControlFlow, Range},
sync::Arc,
};
use sum_tree::{Bias, SumTree};
use sum_tree::{Bias, Dimensions, SumTree};
use time::OffsetDateTime;
use util::{ResultExt as _, TryFutureExt, post_inc};
@ -331,7 +331,9 @@ impl ChannelChat {
.update(&mut cx, |chat, cx| {
if let Some(first_id) = chat.first_loaded_message_id() {
if first_id <= message_id {
let mut cursor = chat.messages.cursor::<(ChannelMessageId, Count)>(&());
let mut cursor = chat
.messages
.cursor::<Dimensions<ChannelMessageId, Count>>(&());
let message_id = ChannelMessageId::Saved(message_id);
cursor.seek(&message_id, Bias::Left);
return ControlFlow::Break(
@ -587,7 +589,9 @@ impl ChannelChat {
.map(|m| m.nonce)
.collect::<HashSet<_>>();
let mut old_cursor = self.messages.cursor::<(ChannelMessageId, Count)>(&());
let mut old_cursor = self
.messages
.cursor::<Dimensions<ChannelMessageId, Count>>(&());
let mut new_messages = old_cursor.slice(&first_message.id, Bias::Left);
let start_ix = old_cursor.start().1.0;
let removed_messages = old_cursor.slice(&last_message.id, Bias::Right);