1use std::num::NonZeroU64;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub struct TokenKey(NonZeroU64);
5
6impl TokenKey {
7 pub const fn new(name: &str) -> Self {
8 let bytes = name.as_bytes();
9 let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
10 let mut index = 0;
11 while index < bytes.len() {
12 hash ^= bytes[index] as u64;
13 hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
14 index += 1;
15 }
16 match NonZeroU64::new(hash) {
17 Some(hash) => Self(hash),
18 None => Self(NonZeroU64::MIN),
19 }
20 }
21}
22
23impl From<&str> for TokenKey {
24 fn from(name: &str) -> Self {
25 Self::new(name)
26 }
27}
28
29impl From<&String> for TokenKey {
30 fn from(name: &String) -> Self {
31 Self::new(name)
32 }
33}
34
35#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
36pub struct Roles {
37 pub fill: Option<TokenKey>,
38 pub fill_end: Option<TokenKey>,
39 pub stroke: Option<TokenKey>,
40 pub pattern: Option<TokenKey>,
41 pub glow: Option<TokenKey>,
42}
43
44impl Roles {
45 pub fn is_none(&self) -> bool {
46 *self == Self::default()
47 }
48}