rune/
params.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::alloc;
#[cfg(feature = "doc")]
use crate::alloc::prelude::*;
use crate::function_meta::{AssociatedName, ToFieldFunction, ToInstance};
use crate::hash::Hash;
use crate::runtime::Protocol;

#[doc(inline)]
pub use rune_core::params::Params;

impl<T, const N: usize> ToInstance for Params<T, N>
where
    T: ToInstance,
{
    #[inline]
    fn to_instance(self) -> alloc::Result<AssociatedName> {
        let info = self.name.to_instance()?;

        Ok(AssociatedName {
            kind: info.kind,
            function_parameters: Hash::parameters(self.parameters),
            #[cfg(feature = "doc")]
            parameter_types: self.parameters.iter().copied().try_collect()?,
        })
    }
}

impl<T, const N: usize> ToFieldFunction for Params<T, N>
where
    T: ToFieldFunction,
{
    #[inline]
    fn to_field_function(self, protocol: &'static Protocol) -> alloc::Result<AssociatedName> {
        let info = self.name.to_field_function(protocol)?;

        Ok(AssociatedName {
            kind: info.kind,
            function_parameters: Hash::parameters(self.parameters),
            #[cfg(feature = "doc")]
            parameter_types: self.parameters.iter().copied().try_collect()?,
        })
    }
}