Make Hasher opaque
This commit is contained in:
parent
e84e0b876c
commit
2ebe09dacb
12 changed files with 36 additions and 20 deletions
|
|
@ -14,7 +14,7 @@ categories = ["gui"]
|
|||
[dependencies]
|
||||
stretch = "0.2"
|
||||
nalgebra = "0.18"
|
||||
twox-hash = "1.3"
|
||||
twox-hash = "1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
ggez = { version = "0.5", git = "https://github.com/hecrj/ggez" }
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> {
|
|||
node.0.compute_layout(geometry::Size::undefined()).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn hash(&self, state: &mut Hasher) {
|
||||
self.widget.hash(state);
|
||||
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,8 +157,8 @@ where
|
|||
self.widget.draw(renderer, layout, cursor_position)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
self.widget.hash(state);
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ where
|
|||
self.element.widget.draw(renderer, layout, cursor_position)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
self.element.widget.hash(state);
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.element.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,18 @@
|
|||
/// The hasher used to compare layouts.
|
||||
pub type Hasher = twox_hash::XxHash;
|
||||
pub struct Hasher(twox_hash::XxHash64);
|
||||
|
||||
impl Default for Hasher {
|
||||
fn default() -> Self {
|
||||
Hasher(twox_hash::XxHash64::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::hash::Hasher for Hasher {
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
self.0.write(bytes)
|
||||
}
|
||||
|
||||
fn finish(&self) -> u64 {
|
||||
self.0.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer> {
|
|||
let root = root.into();
|
||||
|
||||
let hasher = &mut crate::Hasher::default();
|
||||
root.hash(hasher);
|
||||
root.hash_layout(hasher);
|
||||
|
||||
let hash = hasher.finish();
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ impl Cache {
|
|||
let root: Element<'_, (), ()> = Column::new().into();
|
||||
|
||||
let hasher = &mut crate::Hasher::default();
|
||||
root.hash(hasher);
|
||||
root.hash_layout(hasher);
|
||||
|
||||
Cache {
|
||||
hash: hasher.finish(),
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
|
|||
/// [`Widget`]: trait.Widget.html
|
||||
/// [`Layout`]: ../struct.Layout.html
|
||||
/// [`Text`]: text/struct.Text.html
|
||||
fn hash(&self, state: &mut Hasher);
|
||||
fn hash_layout(&self, state: &mut Hasher);
|
||||
|
||||
/// Processes a runtime [`Event`].
|
||||
///
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.style.hash(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.label.hash(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,12 +199,12 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
|
|||
cursor
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.style.hash(state);
|
||||
self.spacing.hash(state);
|
||||
|
||||
for child in &self.children {
|
||||
child.widget.hash(state);
|
||||
child.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.label.hash(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,12 +196,12 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
|
|||
cursor
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.style.hash(state);
|
||||
self.spacing.hash(state);
|
||||
|
||||
for child in &self.children {
|
||||
child.widget.hash(state);
|
||||
child.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.style.hash(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ where
|
|||
MouseCursor::OutOfBounds
|
||||
}
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.style.hash(state);
|
||||
|
||||
self.content.hash(state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue