rune/runtime/const_value/
macros.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
macro_rules! inline_into {
    (
        $(#[$($meta:meta)*])*
        $kind:ident($ty:ty),
        $as:ident,
        $as_mut:ident,
    ) => {
        $(#[$($meta)*])*
        ///
        /// This gets a copy of the value.
        #[inline]
        pub fn $as(&self) -> Result<$ty, RuntimeError> {
            match &self.kind {
                ConstValueKind::Inline(Inline::$kind(value)) => {
                    Ok(*value)
                }
                value => {
                    Err(RuntimeError::expected::<$ty>(value.type_info()))
                }
            }
        }

        $(#[$($meta)*])*
        ///
        /// This gets the value by mutable reference.
        #[inline]
        pub fn $as_mut(&mut self) -> Result<&mut $ty, RuntimeError> {
            match &mut self.kind {
                ConstValueKind::Inline(Inline::$kind(value)) => {
                    Ok(value)
                }
                value => {
                    Err(RuntimeError::expected::<$ty>(value.type_info()))
                }
            }
        }
    }
}