Allow View<T> to be hashed and compared

This commit is contained in:
Antonio Scandurra
2023-10-31 13:34:29 +01:00
parent 163fa3ff16
commit 46a99c5c41
+20 -1
View File
@@ -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<Self> + 'static + Send;
@@ -76,6 +81,20 @@ impl<V> Clone for View<V> {
}
}
impl<V> Hash for View<V> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.model.hash(state);
}
}
impl<V> PartialEq for View<V> {
fn eq(&self, other: &Self) -> bool {
self.model == other.model
}
}
impl<V> Eq for View<V> {}
impl<V: Render, ParentViewState: 'static> Component<ParentViewState> for View<V> {
fn render(self) -> AnyElement<ParentViewState> {
AnyElement::new(EraseViewState {