1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mod glyph_brush;
mod glyph_calculator;
mod owned_section;
mod section;
pub use crate::{glyph_brush::*, glyph_calculator::*, owned_section::*, section::*};
pub use glyph_brush_layout::*;
use glyph_brush_layout::rusttype::*;
#[cfg(not(target_arch = "wasm32"))]
pub type DefaultSectionHasher = twox_hash::RandomXxHashBuilder;
#[cfg(target_arch = "wasm32")]
pub type DefaultSectionHasher = std::hash::BuildHasherDefault<twox_hash::XxHash>;
#[test]
fn default_section_hasher() {
use std::hash::{BuildHasher, Hash, Hasher};
let section_a = Section {
text: "Hovered Tile: Some((0, 0))",
screen_position: (5.0, 60.0),
scale: Scale { x: 20.0, y: 20.0 },
color: [1.0, 1.0, 1.0, 1.0],
..<_>::default()
};
let section_b = Section {
text: "Hovered Tile: Some((1, 0))",
screen_position: (5.0, 60.0),
scale: Scale { x: 20.0, y: 20.0 },
color: [1.0, 1.0, 1.0, 1.0],
..<_>::default()
};
let hash = |s: &Section| {
let s: VariedSection = s.into();
let mut hasher = DefaultSectionHasher::default().build_hasher();
s.hash(&mut hasher);
hasher.finish()
};
assert_ne!(hash(§ion_a), hash(§ion_b));
}