• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mattwparas / steel / 18461079395

13 Oct 2025 09:20AM UTC coverage: 42.731% (-0.9%) from 43.668%
18461079395

Pull #536

github

web-flow
Merge 6f55a8b56 into e378cba22
Pull Request #536: Initial proposal for no_std support

63 of 755 new or added lines in 38 files covered. (8.34%)

73 existing lines in 15 files now uncovered.

12324 of 28841 relevant lines covered (42.73%)

3215759.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/steel-core/src/core/utils.rs
1
// Generates a macro that expands to code snippet to do arity checks
2
// example usage:
3
// arity_check!(length, args, 1);
4
// Expands to:
5
// if args.len() != 1 {
6
//     stop!(ArityMismatch => format!("length expected only one argument, found {}", args.len()))
7
// }
8
// assert!(args.len() == 1);
9

10
// Only compile these helper macros when either the standard library is available
11
// or when higher-level modules that depend on them are enabled. This avoids
12
// unused-macro warnings in minimal `no_std` builds.
13
#[cfg(any(
14
    feature = "std",
15
    feature = "no_std_primitives",
16
    feature = "no_std_values"
17
))]
18
#[cfg(any(
19
    feature = "std",
20
    feature = "no_std_primitives",
21
    feature = "no_std_values"
22
))]
23
use alloc::format;
24

25
#[cfg(any(
26
    feature = "std",
27
    feature = "no_std_primitives",
28
    feature = "no_std_values"
29
))]
NEW
30
pub(crate) fn arity_mismatch_message(name: &'static str, expected: usize, found: usize) -> String {
×
NEW
31
    match expected {
×
NEW
32
        1 => format!("{name} expected only one argument, found {found}"),
×
NEW
33
        other => format!("{name} expected {other} arguments, found {found}"),
×
34
    }
35
}
36

37
#[cfg(any(
38
    feature = "std",
39
    feature = "no_std_primitives",
40
    feature = "no_std_values"
41
))]
42
macro_rules! arity_check_generator {
43
    ($($arity:tt),*) => {
44
        macro_rules! arity_check {
45
            ($name:tt, $args:expr, 1) => {
46
                if $args.len() != 1 {
47
                    stop!(ArityMismatch => crate::core::utils::arity_mismatch_message(stringify!($name), 1, $args.len()))
48
                }
49
                assert!($args.len() == 1);
50
            };
51

52
            $ (
53
                ($name:tt, $args:expr, $arity) => {
54
                    if $args.len() != $arity {
55
                        stop!(ArityMismatch => crate::core::utils::arity_mismatch_message(stringify!($name), $arity, $args.len()))
56
                    }
57
                    assert!($args.len() == $arity);
58
                };
59
            ) *
60
        }
61
    }
62
}
63

64
#[cfg(any(
65
    feature = "std",
66
    feature = "no_std_primitives",
67
    feature = "no_std_values"
68
))]
69
arity_check_generator!(0, 1, 2, 3, 4, 5, 6, 7, 8);
70

71
#[cfg(any(
72
    feature = "std",
73
    feature = "no_std_primitives",
74
    feature = "no_std_values"
75
))]
76
pub(crate) use arity_check;
77

78
// Declares a const for a function that takes an immutable slice to the arguments
79
// e.g.
80
//      declare_const_ref_functions! { LENGTH => length }
81
// expands into
82
//      const LENGTH: SteelVal = SteelVal::FuncV(length)
83
#[cfg(any(
84
    feature = "std",
85
    feature = "no_std_primitives",
86
    feature = "no_std_values"
87
))]
88
macro_rules! declare_const_ref_functions {
89
    ($($name:tt => $func_name:tt),* $(,)? ) => {
90
        $ (
91
            pub(crate) const $name: SteelVal = SteelVal::FuncV($func_name);
92
        ) *
93
    }
94
}
95

96
#[cfg(any(
97
    feature = "std",
98
    feature = "no_std_primitives",
99
    feature = "no_std_values"
100
))]
101
pub(crate) use declare_const_ref_functions;
102

103
// Declares a const for a function that takes an immutable slice to the arguments
104
// e.g.
105
//      declare_const_mut_ref_functions! { CONS => cons }
106
// expands into
107
//      const LENGTH: SteelVal = SteelVal::MutFunc(length)
108
#[cfg(any(
109
    feature = "std",
110
    feature = "no_std_primitives",
111
    feature = "no_std_values"
112
))]
113
macro_rules! declare_const_mut_ref_functions {
114
    ($($name:tt => $func_name:tt),* $(,)? ) => {
115
        $ (
116
            pub(crate) const $name: SteelVal = SteelVal::MutFunc($func_name);
117
        ) *
118
    }
119
}
120

121
#[cfg(any(
122
    feature = "std",
123
    feature = "no_std_primitives",
124
    feature = "no_std_values"
125
))]
126
pub(crate) use declare_const_mut_ref_functions;
127

128
// pub(crate) trait Boxed {
129
//     fn boxed(self) -> Box<Self>;
130
//     fn refcounted(self) -> Rc<Self>;
131
//     fn rc_refcell(self) -> Rc<RefCell<Self>>;
132
// }
133

134
// impl<T> Boxed for T {
135
//     #[inline(always)]
136
//     fn boxed(self) -> Box<T> {
137
//         Box::new(self)
138
//     }
139

140
//     #[inline(always)]
141
//     fn refcounted(self) -> Rc<T> {
142
//         Rc::new(self)
143
//     }
144

145
//     #[inline(always)]
146
//     fn rc_refcell(self) -> Rc<RefCell<T>> {
147
//         Rc::new(RefCell::new(self))
148
//     }
149
// }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc