rune/runtime/const_value/
macros.rs
1macro_rules! inline_into {
2 (
3 $(#[$($meta:meta)*])*
4 $kind:ident($ty:ty),
5 $as:ident,
6 $as_mut:ident,
7 ) => {
8 $(#[$($meta)*])*
9 #[inline]
12 pub fn $as(&self) -> Result<$ty, RuntimeError> {
13 match &self.kind {
14 ConstValueKind::Inline(Inline::$kind(value)) => {
15 Ok(*value)
16 }
17 value => {
18 Err(RuntimeError::expected::<$ty>(value.type_info()))
19 }
20 }
21 }
22
23 $(#[$($meta)*])*
24 #[inline]
27 pub fn $as_mut(&mut self) -> Result<&mut $ty, RuntimeError> {
28 match &mut self.kind {
29 ConstValueKind::Inline(Inline::$kind(value)) => {
30 Ok(value)
31 }
32 value => {
33 Err(RuntimeError::expected::<$ty>(value.type_info()))
34 }
35 }
36 }
37 }
38}