rune_core/params.rs
1use crate::hash::{Hash, IntoHash};
2
3/// Helper to register a parameterized function.
4///
5/// This is used to wrap the name of the function in order to associated
6/// parameters with it.
7///
8/// # Examples
9///
10/// ```
11/// use rune::{Params, TypeHash};
12/// use rune::hash::IntoHash;
13/// use rune::runtime::Vec;
14///
15/// let params = Params::new("collect", []);
16/// assert_eq!(params.into_hash(), "collect".into_hash());
17///
18/// let params = Params::new("collect", [Vec::HASH]);
19/// assert_eq!(params.into_hash(), "collect".into_hash());
20/// ```
21#[derive(Clone)]
22#[non_exhaustive]
23pub struct Params<T, const N: usize> {
24 #[doc(hidden)]
25 pub name: T,
26 #[doc(hidden)]
27 pub parameters: [Hash; N],
28}
29
30impl<T, const N: usize> Params<T, N> {
31 /// Construct a new parameters wrapper.
32 ///
33 /// # Examples
34 ///
35 /// ```
36 /// use rune::{Params, TypeHash};
37 /// use rune::hash::IntoHash;
38 /// use rune::runtime::Vec;
39 ///
40 /// let params = Params::new("collect", []);
41 /// assert_eq!(params.into_hash(), "collect".into_hash());
42 ///
43 /// let params = Params::new("collect", [Vec::HASH]);
44 /// assert_eq!(params.into_hash(), "collect".into_hash());
45 /// ```
46 pub const fn new(name: T, parameters: [Hash; N]) -> Self {
47 Self { name, parameters }
48 }
49}
50
51impl<T, const N: usize> IntoHash for Params<T, N>
52where
53 T: IntoHash,
54{
55 #[inline]
56 fn into_hash(self) -> Hash {
57 self.name.into_hash()
58 }
59}