From fbb49e9b65d937acd8a48d560ee21992989137bf Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 29 Aug 2025 13:33:12 +0300 Subject: [PATCH] chore(spaces): simplify the `SpaceGraph` interfaces --- crates/matrix-sdk-ui/src/spaces/graph.rs | 12 ++++++------ crates/matrix-sdk-ui/src/spaces/room.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/spaces/graph.rs b/crates/matrix-sdk-ui/src/spaces/graph.rs index bb7240056..b8c0a1b22 100644 --- a/crates/matrix-sdk-ui/src/spaces/graph.rs +++ b/crates/matrix-sdk-ui/src/spaces/graph.rs @@ -45,30 +45,30 @@ impl Default for SpaceGraph { impl SpaceGraph { /// Creates a new empty space graph containing no nodes or edges. - pub fn new() -> Self { + pub(super) fn new() -> Self { Self { nodes: BTreeMap::new() } } /// Returns the root nodes of the graph, which are nodes without any /// parents. - pub fn root_nodes(&self) -> Vec<&OwnedRoomId> { + pub(super) fn root_nodes(&self) -> Vec<&OwnedRoomId> { self.nodes.values().filter(|node| node.parents.is_empty()).map(|node| &node.id).collect() } /// Returns the children of a given node. If the node does not exist, it /// returns an empty vector. - pub fn children_of(&self, node_id: &OwnedRoomId) -> Vec<&OwnedRoomId> { + pub(super) fn children_of(&self, node_id: &OwnedRoomId) -> Vec<&OwnedRoomId> { self.nodes.get(node_id).map_or(vec![], |node| node.children.iter().collect()) } /// Adds a node to the graph. If the node already exists, it does nothing. - pub fn add_node(&mut self, node_id: OwnedRoomId) { + pub(super) fn add_node(&mut self, node_id: OwnedRoomId) { self.nodes.entry(node_id.clone()).or_insert(SpaceGraphNode::new(node_id)); } /// Adds a directed edge from `parent_id` to `child_id`, creating nodes if /// they do not already exist in the graph. - pub fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) { + pub(super) fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) { self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone())); self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id.clone())); @@ -80,7 +80,7 @@ impl SpaceGraph { /// Removes cycles in the graph by performing a depth-first search (DFS) and /// remembering the visited nodes. If a node is revisited while still in the /// current path (i.e. it's on the stack), it indicates a cycle. - pub fn remove_cycles(&mut self) { + pub(super) fn remove_cycles(&mut self) { let mut visited = BTreeSet::new(); let mut stack = BTreeSet::new(); diff --git a/crates/matrix-sdk-ui/src/spaces/room.rs b/crates/matrix-sdk-ui/src/spaces/room.rs index 774b0d3dd..d44063535 100644 --- a/crates/matrix-sdk-ui/src/spaces/room.rs +++ b/crates/matrix-sdk-ui/src/spaces/room.rs @@ -78,7 +78,7 @@ impl SpaceRoom { } /// Build a `SpaceRoom` from a room already known to this client. - pub fn new_from_known(known_room: Room, children_count: u64) -> Self { + pub(crate) fn new_from_known(known_room: Room, children_count: u64) -> Self { let room_info = known_room.clone_info(); Self {