From 46a99c5c41c29ae428356f2115bedc8ff6b08ae9 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 31 Oct 2023 13:34:29 +0100 Subject: [PATCH] Allow View to be hashed and compared --- crates/gpui2/src/view.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index 8bef25b92d796c7113ac3f165d8f85cbf7127985..dfc294bc05f0d3377791d6eb254e2ba9882a06ab 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -4,7 +4,12 @@ use crate::{ Size, ViewContext, VisualContext, WeakModel, WindowContext, }; use anyhow::{Context, Result}; -use std::{any::TypeId, marker::PhantomData, sync::Arc}; +use std::{ + any::TypeId, + hash::{Hash, Hasher}, + marker::PhantomData, + sync::Arc, +}; pub trait Render: 'static + Sized { type Element: Element + 'static + Send; @@ -76,6 +81,20 @@ impl Clone for View { } } +impl Hash for View { + fn hash(&self, state: &mut H) { + self.model.hash(state); + } +} + +impl PartialEq for View { + fn eq(&self, other: &Self) -> bool { + self.model == other.model + } +} + +impl Eq for View {} + impl Component for View { fn render(self) -> AnyElement { AnyElement::new(EraseViewState {