rune_core/hash/
into_hash.rs

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
use crate::hash::Hash;
use crate::protocol::Protocol;

mod sealed {
    use crate::hash::Hash;
    use crate::params::Params;
    use crate::protocol::Protocol;

    pub trait Sealed {}

    impl Sealed for &str {}
    impl Sealed for Hash {}
    impl Sealed for &Protocol {}
    impl<T, const N: usize> Sealed for Params<T, N> {}
}

/// Trait for types which can be converted into a
/// [Hash][struct@crate::hash::Hash].
pub trait IntoHash: self::sealed::Sealed {
    /// Convert current type into a hash.
    fn into_hash(self) -> Hash;
}

impl IntoHash for Hash {
    #[inline]
    fn into_hash(self) -> Hash {
        self
    }
}

impl IntoHash for &str {
    #[inline]
    fn into_hash(self) -> Hash {
        Hash::ident(self)
    }
}

impl IntoHash for &Protocol {
    #[inline]
    fn into_hash(self) -> Hash {
        self.hash
    }
}