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

mattwparas / steel / 17772690385

16 Sep 2025 04:36PM UTC coverage: 43.331% (+0.04%) from 43.289%
17772690385

Pull #519

github

web-flow
Merge 98d4fd22c into 3c10433b9
Pull Request #519: fix a bunch more clippy lints

56 of 123 new or added lines in 30 files covered. (45.53%)

8 existing lines in 3 files now uncovered.

12416 of 28654 relevant lines covered (43.33%)

2985398.75 hits per line

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

32.11
/crates/steel-core/src/primitives.rs
1
pub mod bytevectors;
2
pub mod contracts;
3
mod control;
4
mod fs;
5
pub mod hashmaps;
6
pub mod hashsets;
7
pub mod http;
8
mod io;
9
pub mod lists;
10
pub mod meta_ops;
11
/// Implements numbers as defined in section 6.2 of the R7RS spec.
12
pub mod numbers;
13

14
#[cfg(not(target_family = "wasm"))]
15
pub mod polling;
16

17
pub mod ports;
18
pub mod process;
19
pub mod random;
20
mod streams;
21
pub mod strings;
22
mod symbols;
23
pub mod tcp;
24
pub mod time;
25
pub mod transducers;
26
mod utils;
27
pub mod vectors;
28

29
// This is for boot strapping the package
30
// manager with an embedded git implementation,
31
// as to not require depending on the system git.
32
pub mod git;
33

34
pub mod hashes;
35

36
use crate::gc::{Gc, GcMut};
37
use crate::rvals::{FromSteelVal, IntoSteelVal, SteelByteVector};
38
use crate::rvals::{
39
    FunctionSignature, PrimitiveAsRef, PrimitiveAsRefMut, SteelHashMap, SteelHashSet, SteelVal,
40
    SteelVector,
41
};
42
use crate::values::closed::HeapRef;
43
use crate::values::lists::List;
44
use crate::values::port::SteelPort;
45
use crate::values::structs::UserDefinedStruct;
46
use crate::values::Vector;
47
use crate::{
48
    rerrs::{ErrorKind, SteelErr},
49
    rvals::SteelString,
50
};
51
pub use control::ControlOperations;
52
pub use fs::{fs_module, fs_module_sandbox};
53
pub use io::IoFunctions;
54
pub use lists::UnRecoverableResult;
55
pub use meta_ops::MetaOperations;
56
use num_bigint::BigInt;
57
use num_rational::{BigRational, Rational32};
58
use num_traits::ToPrimitive;
59
pub use numbers::{add_primitive, divide_primitive, multiply_primitive, subtract_primitive};
60
pub use ports::port_module;
61
use std::convert::TryFrom;
62
use std::result;
63
pub use streams::StreamOperations;
64
pub use strings::string_module;
65
pub use symbols::symbol_module;
66

67
macro_rules! try_from_impl {
68
    ($type:ident => $($body:ty),*) => {
69
        $(
70
            impl TryFrom<SteelVal> for $body {
71
                type Error = SteelErr;
72
                #[inline]
73
                fn try_from(value: SteelVal) -> result::Result<Self, Self::Error> {
×
74
                    match value {
×
75
                        SteelVal::$type(x) => Ok(x.clone() as $body),
×
76
                        _ => Err(SteelErr::new(ErrorKind::ConversionError, format!("Expected number, found: {}", value))),
×
77
                    }
78
                }
79
            }
80

81
            impl TryFrom<&SteelVal> for $body {
82
                type Error = SteelErr;
83
                #[inline]
84
                fn try_from(value: &SteelVal) -> result::Result<Self, Self::Error> {
×
85
                    match value {
×
86
                        SteelVal::$type(x) => Ok(x.clone() as $body),
×
87
                        _ => Err(SteelErr::new(ErrorKind::ConversionError, format!("Expected number, found: {}", value))),
×
88
                    }
89
                }
90
            }
91

92
            impl FromSteelVal for $body {
93
                #[inline]
94
                fn from_steelval(value: &SteelVal) -> result::Result<Self, SteelErr> {
14,489,722✔
95
                    match value {
14,489,722✔
96
                        SteelVal::$type(x) => Ok(x.clone() as $body),
14,489,722✔
97
                        _ => Err(SteelErr::new(ErrorKind::ConversionError, format!("Expected number, found: {}", value))),
×
98
                    }
99
                }
100
            }
101

102
        )*
103
    };
104
}
105

106
macro_rules! from_f64 {
107
    ($($body:ty),*) => {
108
        $(
109
            impl From<$body> for SteelVal {
110
                #[inline]
111
                fn from(val: $body) -> SteelVal {
1✔
112
                    SteelVal::NumV(val as f64)
1✔
113
                }
114
            }
115

116
            impl IntoSteelVal for $body {
117
                #[inline]
118
                fn into_steelval(self) -> Result<SteelVal, SteelErr> {
20,208,563✔
119
                    Ok(SteelVal::NumV(self as f64))
20,208,563✔
120
                }
121
            }
122
        )*
123
    };
124
}
125

126
macro_rules! from_for_isize {
127
    ($($body:ty),*) => {
128
        $(
129
            impl From<$body> for SteelVal {
130
                #[inline]
131
                fn from(val: $body) -> SteelVal {
2✔
132
                    SteelVal::IntV(val as isize)
2✔
133
                }
134
            }
135

136
            impl IntoSteelVal for $body {
137
                #[inline]
138
                fn into_steelval(self) -> Result<SteelVal, SteelErr> {
16,669,407✔
139
                    Ok(SteelVal::IntV(self as isize))
16,669,407✔
140
                }
141
            }
142
        )*
143
    };
144
}
145

146
impl From<i64> for SteelVal {
147
    fn from(value: i64) -> Self {
×
148
        if let Ok(converted) = TryInto::<isize>::try_into(value) {
×
149
            SteelVal::IntV(converted)
×
150
        } else {
151
            SteelVal::BigNum(Gc::new(value.into()))
×
152
        }
153
    }
154
}
155

156
impl FromSteelVal for u8 {
157
    #[inline]
158
    fn from_steelval(val: &SteelVal) -> crate::rvals::Result<Self> {
4,950,325✔
159
        match val {
4,950,325✔
160
            SteelVal::IntV(v) => (*v).try_into().map_err(|_err| {
4,950,325✔
161
                SteelErr::new(
×
162
                    ErrorKind::ConversionError,
×
163
                    format!("Unable to convert isize to u8: {}", v),
×
164
                )
165
            }),
166
            SteelVal::BigNum(n) => n.as_ref().try_into().map_err(|_err| {
×
167
                SteelErr::new(
×
168
                    ErrorKind::ConversionError,
×
169
                    format!("Unable to convert bignum to u8: {:?}", n),
×
170
                )
171
            }),
172
            _ => Err(SteelErr::new(
×
173
                ErrorKind::ConversionError,
×
174
                format!("Unable to convert steelval to u8: {}", val),
×
175
            )),
176
        }
177
    }
178
}
179

180
impl From<usize> for SteelVal {
181
    #[inline]
182
    fn from(value: usize) -> Self {
25✔
183
        if value > isize::MAX as usize {
25✔
184
            SteelVal::BigNum(Gc::new(value.into()))
×
185
        } else {
186
            SteelVal::IntV(value as isize)
25✔
187
        }
188
    }
189
}
190

191
impl IntoSteelVal for usize {
192
    #[inline]
193
    fn into_steelval(self) -> crate::rvals::Result<SteelVal> {
25✔
194
        Ok(SteelVal::from(self))
25✔
195
    }
196
}
197

198
impl IntoSteelVal for u128 {
199
    fn into_steelval(self) -> crate::rvals::Result<SteelVal> {
×
200
        Ok(SteelVal::from(self))
×
201
    }
202
}
203

204
impl From<u128> for SteelVal {
205
    fn from(value: u128) -> Self {
×
206
        if value > isize::MAX as u128 {
×
207
            SteelVal::BigNum(Gc::new(value.into()))
×
208
        } else {
209
            SteelVal::IntV(value as isize)
×
210
        }
211
    }
212
}
213

214
impl IntoSteelVal for i64 {
215
    #[inline]
216
    fn into_steelval(self) -> crate::rvals::Result<SteelVal> {
×
217
        Ok(self.into())
×
218
    }
219
}
220

221
impl FromSteelVal for i64 {
222
    fn from_steelval(val: &SteelVal) -> crate::rvals::Result<Self> {
×
223
        match val {
×
224
            SteelVal::IntV(v) => (*v).try_into().map_err(|_err| {
×
225
                SteelErr::new(
×
226
                    ErrorKind::ConversionError,
×
227
                    format!("Unable to convert i64 to isize: {}", v),
×
228
                )
229
            }),
230
            SteelVal::BigNum(n) => n.as_ref().try_into().map_err(|_err| {
×
231
                SteelErr::new(
×
232
                    ErrorKind::ConversionError,
×
233
                    format!("Unable to convert bignum to isize: {:?}", n),
×
234
                )
235
            }),
236
            _ => Err(SteelErr::new(
×
237
                ErrorKind::ConversionError,
×
238
                format!("Unable to convert steelval to isize: {}", val),
×
239
            )),
240
        }
241
    }
242
}
243

244
impl From<char> for SteelVal {
245
    #[inline]
246
    fn from(val: char) -> SteelVal {
×
247
        SteelVal::CharV(val)
×
248
    }
249
}
250

251
impl IntoSteelVal for char {
252
    #[inline]
253
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
417✔
254
        Ok(SteelVal::CharV(self))
417✔
255
    }
256
}
257

258
impl FromSteelVal for char {
259
    fn from_steelval(val: &SteelVal) -> Result<Self, SteelErr> {
4,619,144✔
260
        if let SteelVal::CharV(c) = val {
9,238,288✔
261
            Ok(*c)
262
        } else {
263
            Err(SteelErr::new(
×
264
                ErrorKind::ConversionError,
×
265
                "Expected character".to_string(),
×
266
            ))
267
        }
268
    }
269
}
270

271
impl<T: Into<SteelVal>> From<Option<T>> for SteelVal {
272
    #[inline]
273
    fn from(val: Option<T>) -> SteelVal {
×
274
        if let Some(s) = val {
×
275
            s.into()
×
276
        } else {
277
            SteelVal::BoolV(true)
×
278
        }
279
    }
280
}
281

282
impl<T: IntoSteelVal> IntoSteelVal for Option<T> {
283
    #[inline]
284
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
1,670✔
285
        if let Some(s) = self {
3,316✔
286
            s.into_steelval()
×
287
        } else {
288
            Ok(SteelVal::BoolV(false))
24✔
289
        }
290
    }
291
}
292

293
impl<T: FromSteelVal> FromSteelVal for Option<T> {
294
    #[inline]
295
    fn from_steelval(val: &SteelVal) -> Result<Self, SteelErr> {
3,723✔
296
        if val.is_truthy() {
7,446✔
297
            Ok(Some(T::from_steelval(val)?))
5,116✔
298
        } else {
299
            Ok(None)
1,165✔
300
        }
301
    }
302
}
303

304
impl FromSteelVal for SteelVal {
305
    #[inline]
306
    fn from_steelval(val: &SteelVal) -> Result<Self, SteelErr> {
14,490,858✔
307
        Ok(val.clone())
14,490,858✔
308
    }
309
}
310

311
impl FromSteelVal for () {
312
    fn from_steelval(val: &SteelVal) -> Result<Self, SteelErr> {
×
313
        if let SteelVal::Void = val {
×
314
            Ok(())
×
315
        } else {
316
            crate::stop!(ConversionError => "could not convert value to unit type")
×
317
        }
318
    }
319
}
320

321
impl IntoSteelVal for () {
322
    #[inline]
323
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
2✔
324
        Ok(SteelVal::Void)
2✔
325
    }
326
}
327

328
impl From<()> for SteelVal {
329
    #[inline]
330
    fn from(_: ()) -> SteelVal {
×
331
        SteelVal::Void
×
332
    }
333
}
334

335
impl IntoSteelVal for Rational32 {
336
    #[inline]
337
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
488✔
338
        if self.is_integer() {
976✔
339
            self.numer().into_steelval()
×
340
        } else {
341
            Ok(SteelVal::Rational(self))
488✔
342
        }
343
    }
344
}
345

346
impl IntoSteelVal for BigInt {
347
    #[inline]
348
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
276,596✔
349
        match self.to_isize() {
276,596✔
350
            Some(i) => i.into_steelval(),
×
351
            None => Ok(SteelVal::BigNum(crate::gc::Gc::new(self))),
276,596✔
352
        }
353
    }
354
}
355

356
impl IntoSteelVal for BigRational {
357
    #[inline]
358
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
80✔
359
        if self.is_integer() {
160✔
360
            let (n, _) = self.into();
×
361
            return n.into_steelval();
×
362
        }
363
        match (self.numer().to_i32(), self.denom().to_i32()) {
×
364
            (Some(n), Some(d)) => Rational32::new(n, d).into_steelval(),
×
365
            _ => Ok(SteelVal::BigRational(Gc::new(self))),
80✔
366
        }
367
    }
368
}
369

370
from_f64!(f64, f32);
371
from_for_isize!(i32, i16, i8, u8, u16, u32, u64, isize);
372
try_from_impl!(NumV => f64, f32);
373
try_from_impl!(IntV => i32, i16, i8, u16, u32, u64, usize, isize);
374

375
impl TryFrom<SteelVal> for String {
376
    type Error = SteelErr;
377
    #[inline]
378
    fn try_from(value: SteelVal) -> result::Result<Self, Self::Error> {
×
379
        match value {
×
380
            SteelVal::StringV(ref x) => Ok(x.to_string()),
×
381
            SteelVal::SymbolV(ref x) => Ok(x.to_string()),
×
382
            _ => Err(SteelErr::new(
×
383
                ErrorKind::ConversionError,
×
384
                "Expected string".to_string(),
×
385
            )),
386
        }
387
    }
388
}
389

390
impl From<SteelVal> for Gc<SteelVal> {
391
    #[inline]
392
    fn from(val: SteelVal) -> Self {
×
393
        Gc::new(val)
×
394
    }
395
}
396

397
impl From<Gc<SteelVal>> for SteelVal {
398
    #[inline]
399
    fn from(val: Gc<SteelVal>) -> Self {
11✔
400
        (*val).clone()
22✔
401
    }
402
}
403

404
impl FromSteelVal for String {
405
    #[inline]
406
    fn from_steelval(val: &SteelVal) -> Result<Self, SteelErr> {
5,691✔
407
        match val {
5,691✔
408
            SteelVal::StringV(s) | SteelVal::SymbolV(s) => Ok(s.to_string()),
11,382✔
409
            _ => Err(SteelErr::new(
×
410
                ErrorKind::ConversionError,
×
411
                format!("Expected string, found: {val}"),
×
412
            )),
413
        }
414
    }
415
}
416

417
impl TryFrom<&SteelVal> for String {
418
    type Error = SteelErr;
419
    #[inline]
420
    fn try_from(value: &SteelVal) -> result::Result<Self, Self::Error> {
1✔
421
        match value {
1✔
422
            SteelVal::StringV(x) => Ok(x.to_string()),
1✔
423
            SteelVal::SymbolV(x) => Ok(x.to_string()),
×
424
            _ => Err(SteelErr::new(
×
425
                ErrorKind::ConversionError,
×
426
                "Expected string".to_string(),
×
427
            )),
428
        }
429
    }
430
}
431

432
impl From<String> for SteelVal {
433
    #[inline]
434
    fn from(val: String) -> SteelVal {
×
435
        SteelVal::StringV(val.into())
×
436
    }
437
}
438

439
impl IntoSteelVal for &str {
440
    #[inline]
441
    fn into_steelval(self) -> crate::rvals::Result<SteelVal> {
×
442
        Ok(SteelVal::StringV(self.into()))
×
443
    }
444
}
445

446
impl FromSteelVal for SteelString {
447
    #[inline]
UNCOV
448
    fn from_steelval(val: &SteelVal) -> crate::rvals::Result<Self> {
×
UNCOV
449
        if let SteelVal::StringV(s) = val {
×
450
            Ok(s.clone())
×
451
        } else {
452
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel string", val))
×
453
        }
454
    }
455
}
456

457
pub enum Either<L, R> {
458
    Left(L),
459
    Right(R),
460
}
461

462
impl<'a, L: PrimitiveAsRef<'a>, R: PrimitiveAsRef<'a>> PrimitiveAsRef<'a> for Either<L, R> {
463
    #[inline(always)]
464
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
22,066✔
465
        let left_type_name = std::any::type_name::<L>();
44,132✔
466
        let right_type_name = std::any::type_name::<R>();
44,132✔
467

468
        let error_thunk = crate::throw!(ConversionError => format!("Cannot convert steel value to the specified type: {} or {}", left_type_name, right_type_name));
44,132✔
469

470
        Self::maybe_primitive_as_ref(val).ok_or_else(error_thunk)
88,264✔
471
    }
472

473
    #[inline(always)]
474
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
22,066✔
475
        L::maybe_primitive_as_ref(val)
44,132✔
476
            .map(Either::Left)
22,066✔
477
            .or_else(|| R::maybe_primitive_as_ref(val).map(Either::Right))
52,216✔
478
    }
479
}
480

481
impl<'a> PrimitiveAsRef<'a> for &'a SteelByteVector {
482
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
20,053✔
483
        Self::maybe_primitive_as_ref(val).ok_or_else(
60,159✔
484
            crate::throw!(ConversionError => format!("Cannot convert value to bytevector: {}", val)),
20,053✔
485
        )
486
    }
487

488
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
20,053✔
489
        if let SteelVal::ByteVector(s) = val {
40,106✔
490
            Some(s)
×
491
        } else {
492
            None
×
493
        }
494
    }
495
}
496

497
impl<'a> PrimitiveAsRef<'a> for &'a UserDefinedStruct {
498
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
499
        Self::maybe_primitive_as_ref(val).ok_or_else(
×
500
            crate::throw!(ConversionError => format!("Cannot convert value to struct: {}", val)),
×
501
        )
502
    }
503

504
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
505
        if let SteelVal::CustomStruct(s) = val {
×
506
            Some(s)
×
507
        } else {
508
            None
×
509
        }
510
    }
511
}
512

513
impl<'a> PrimitiveAsRef<'a> for &'a GcMut<SteelVal> {
514
    #[inline(always)]
515
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
516
        if let SteelVal::Boxed(c) = val {
×
517
            Ok(c)
×
518
        } else {
519
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel boxed value", val))
×
520
        }
521
    }
522

523
    #[inline(always)]
524
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
525
        if let SteelVal::Boxed(c) = val {
×
526
            Some(c)
×
527
        } else {
528
            None
×
529
        }
530
    }
531
}
532

533
impl<'a> PrimitiveAsRef<'a> for &'a HeapRef<SteelVal> {
534
    #[inline(always)]
535
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
8,026,368✔
536
        if let SteelVal::HeapAllocated(b) = val {
16,052,736✔
537
            Ok(b)
×
538
        } else {
539
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel box", val))
×
540
        }
541
    }
542

543
    #[inline(always)]
544
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
545
        if let SteelVal::HeapAllocated(b) = val {
×
546
            Some(b)
×
547
        } else {
548
            None
×
549
        }
550
    }
551
}
552

553
impl<'a> PrimitiveAsRef<'a> for &'a char {
554
    #[inline(always)]
555
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
398✔
556
        if let SteelVal::CharV(c) = val {
796✔
557
            Ok(c)
×
558
        } else {
559
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel character", val))
×
560
        }
561
    }
562

563
    #[inline(always)]
564
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
565
        if let SteelVal::CharV(c) = val {
×
566
            Some(c)
×
567
        } else {
568
            None
×
569
        }
570
    }
571
}
572

573
impl<'a> PrimitiveAsRef<'a> for char {
574
    #[inline(always)]
575
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
80,698,652✔
576
        if let SteelVal::CharV(c) = val {
161,397,304✔
577
            Ok(*c)
×
578
        } else {
579
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel character", val))
×
580
        }
581
    }
582

583
    #[inline(always)]
584
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
585
        if let SteelVal::CharV(c) = val {
×
586
            Some(*c)
×
587
        } else {
588
            None
×
589
        }
590
    }
591
}
592

593
impl<'a> PrimitiveAsRef<'a> for isize {
594
    #[inline(always)]
595
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
44✔
596
        if let SteelVal::IntV(i) = val {
88✔
597
            Ok(*i)
×
598
        } else {
599
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel int", val))
×
600
        }
601
    }
602

603
    #[inline(always)]
604
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
605
        if let SteelVal::IntV(i) = val {
×
606
            Some(*i)
×
607
        } else {
608
            None
×
609
        }
610
    }
611
}
612

613
impl<'a> PrimitiveAsRef<'a> for &'a Gc<Vector<SteelVal>> {
614
    #[inline(always)]
615
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
616
        if let SteelVal::VectorV(p) = val {
×
617
            Ok(&p.0)
×
618
        } else {
619
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel vector", val))
×
620
        }
621
    }
622

623
    #[inline(always)]
624
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
625
        if let SteelVal::VectorV(p) = val {
×
626
            Some(&p.0)
×
627
        } else {
628
            None
×
629
        }
630
    }
631
}
632

633
impl<'a> PrimitiveAsRef<'a> for &'a SteelVector {
634
    #[inline(always)]
635
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
2,008✔
636
        if let SteelVal::VectorV(p) = val {
4,016✔
637
            Ok(p)
×
638
        } else {
639
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel vector", val))
×
640
        }
641
    }
642

643
    #[inline(always)]
644
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
22,062✔
645
        if let SteelVal::VectorV(p) = val {
34,084✔
646
            Some(p)
×
647
        } else {
648
            None
10,040✔
649
        }
650
    }
651
}
652

653
impl<'a> PrimitiveAsRef<'a> for &'a Gc<crate::values::HashSet<SteelVal>> {
654
    #[inline(always)]
655
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
656
        if let SteelVal::HashSetV(p) = val {
×
657
            Ok(&p.0)
×
658
        } else {
659
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel hashset", val))
×
660
        }
661
    }
662

663
    #[inline(always)]
664
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
665
        if let SteelVal::HashSetV(p) = val {
×
666
            Some(&p.0)
×
667
        } else {
668
            None
×
669
        }
670
    }
671
}
672

673
impl<'a> PrimitiveAsRef<'a> for &'a SteelHashSet {
674
    #[inline(always)]
675
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
59✔
676
        if let SteelVal::HashSetV(p) = val {
118✔
677
            Ok(p)
×
678
        } else {
679
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel hashset", val))
×
680
        }
681
    }
682

683
    #[inline(always)]
684
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
685
        if let SteelVal::HashSetV(p) = val {
×
686
            Some(p)
×
687
        } else {
688
            None
×
689
        }
690
    }
691
}
692

693
impl<'a> PrimitiveAsRef<'a> for &'a HeapRef<Vec<SteelVal>> {
694
    #[inline(always)]
695
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
14,490,926✔
696
        if let SteelVal::MutableVector(p) = val {
28,981,852✔
697
            Ok(p)
×
698
        } else {
699
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel mutable vector", val))
×
700
        }
701
    }
702

703
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
10,054✔
704
        if let SteelVal::MutableVector(p) = val {
20,098✔
705
            Some(p)
×
706
        } else {
707
            None
10✔
708
        }
709
    }
710
}
711

712
impl<'a> PrimitiveAsRef<'a> for &'a SteelPort {
713
    #[inline(always)]
714
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
31,714,207✔
715
        if let SteelVal::PortV(p) = val {
63,428,414✔
716
            Ok(p)
×
717
        } else {
718
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel port", val))
×
719
        }
720
    }
721

722
    #[inline(always)]
723
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
724
        if let SteelVal::PortV(p) = val {
×
725
            Some(p)
×
726
        } else {
727
            None
×
728
        }
729
    }
730
}
731

732
impl<'a> PrimitiveAsRef<'a> for &'a List<SteelVal> {
733
    #[inline(always)]
734
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
633,463✔
735
        if let SteelVal::ListV(l) = val {
1,266,926✔
736
            Ok(l)
×
737
        } else {
UNCOV
738
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to steel list", val))
×
739
        }
740
    }
741

742
    #[inline(always)]
743
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
744
        if let SteelVal::ListV(l) = val {
×
745
            Some(l)
×
746
        } else {
747
            None
×
748
        }
749
    }
750
}
751

752
impl<'a> PrimitiveAsRef<'a> for &'a SteelVal {
753
    #[inline(always)]
754
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
14,046✔
755
        Ok(val)
14,046✔
756
    }
757

758
    #[inline(always)]
759
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
760
        Some(val)
×
761
    }
762
}
763

764
impl<'a> PrimitiveAsRefMut<'a> for &'a mut SteelVal {
765
    #[inline(always)]
UNCOV
766
    fn primitive_as_ref(val: &'a mut SteelVal) -> crate::rvals::Result<Self> {
×
UNCOV
767
        Ok(val)
×
768
    }
769

770
    #[inline(always)]
771
    fn maybe_primitive_as_ref(val: &'a mut SteelVal) -> Option<Self> {
×
772
        Some(val)
×
773
    }
774
}
775

776
impl<'a> PrimitiveAsRef<'a> for &'a SteelString {
777
    #[inline(always)]
778
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
779
        if let SteelVal::StringV(s) = val {
×
780
            Ok(s)
×
781
        } else {
782
            crate::stop!(TypeMismatch => format!("Cannot convert steel value: {} to steel string", val))
×
783
        }
784
    }
785

786
    #[inline(always)]
787
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
788
        if let SteelVal::StringV(s) = val {
×
789
            Some(s)
×
790
        } else {
791
            None
×
792
        }
793
    }
794
}
795

796
impl<'a> PrimitiveAsRef<'a> for &'a Gc<crate::values::HashMap<SteelVal, SteelVal>> {
797
    #[inline(always)]
798
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
35,549✔
799
        if let SteelVal::HashMapV(hm) = val {
71,098✔
800
            Ok(&hm.0)
×
801
        } else {
802
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to hashmap", val))
×
803
        }
804
    }
805

806
    #[inline(always)]
807
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
808
        if let SteelVal::HashMapV(hm) = val {
×
809
            Some(&hm.0)
×
810
        } else {
811
            None
×
812
        }
813
    }
814
}
815

816
impl<'a> PrimitiveAsRefMut<'a> for &'a mut Gc<crate::values::HashMap<SteelVal, SteelVal>> {
817
    #[inline(always)]
818
    fn primitive_as_ref(val: &'a mut SteelVal) -> crate::rvals::Result<Self> {
×
819
        if let SteelVal::HashMapV(hm) = val {
×
820
            Ok(&mut hm.0)
×
821
        } else {
822
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to hashmap", val))
×
823
        }
824
    }
825

826
    #[inline(always)]
827
    fn maybe_primitive_as_ref(val: &'a mut SteelVal) -> Option<Self> {
×
828
        if let SteelVal::HashMapV(hm) = val {
×
829
            Some(&mut hm.0)
×
830
        } else {
831
            None
×
832
        }
833
    }
834
}
835

836
impl<'a> PrimitiveAsRefMut<'a> for &'a mut SteelByteVector {
837
    #[inline(always)]
838
    fn primitive_as_ref(val: &'a mut SteelVal) -> crate::rvals::Result<Self> {
4,950,281✔
839
        if let SteelVal::ByteVector(hm) = val {
9,900,562✔
840
            Ok(hm)
×
841
        } else {
842
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to bytevector", val))
×
843
        }
844
    }
845

846
    #[inline(always)]
847
    fn maybe_primitive_as_ref(val: &'a mut SteelVal) -> Option<Self> {
×
848
        if let SteelVal::ByteVector(hm) = val {
×
849
            Some(hm)
×
850
        } else {
851
            None
×
852
        }
853
    }
854
}
855

856
impl<'a> PrimitiveAsRef<'a> for &'a SteelHashMap {
857
    #[inline(always)]
858
    fn primitive_as_ref(val: &'a SteelVal) -> crate::rvals::Result<Self> {
×
859
        if let SteelVal::HashMapV(hm) = val {
×
860
            Ok(hm)
×
861
        } else {
862
            crate::stop!(ConversionError => format!("Cannot convert steel value: {} to hashmap", val))
×
863
        }
864
    }
865

866
    #[inline(always)]
867
    fn maybe_primitive_as_ref(val: &'a SteelVal) -> Option<Self> {
×
868
        if let SteelVal::HashMapV(hm) = val {
×
869
            Some(hm)
×
870
        } else {
871
            None
×
872
        }
873
    }
874
}
875

876
impl IntoSteelVal for String {
877
    #[inline(always)]
878
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
1✔
879
        Ok(SteelVal::StringV(self.into()))
1✔
880
    }
881
}
882

883
impl IntoSteelVal for SteelString {
884
    #[inline(always)]
885
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
×
886
        Ok(SteelVal::StringV(self))
×
887
    }
888
}
889

890
impl From<String> for Gc<SteelVal> {
891
    #[inline(always)]
892
    fn from(val: String) -> Gc<SteelVal> {
×
893
        Gc::new(val.into())
×
894
    }
895
}
896

897
impl From<bool> for SteelVal {
898
    #[inline(always)]
899
    fn from(val: bool) -> SteelVal {
24,124✔
900
        SteelVal::BoolV(val)
24,124✔
901
    }
902
}
903

904
impl FromSteelVal for bool {
905
    #[inline(always)]
906
    fn from_steelval(val: &SteelVal) -> crate::rvals::Result<bool> {
700✔
907
        if let SteelVal::BoolV(b) = val {
1,400✔
908
            Ok(*b)
×
909
        } else {
910
            crate::stop!(ConversionError => format!("Cannot convert steel value: {val} to boolean"))
×
911
        }
912
    }
913
}
914

915
impl IntoSteelVal for bool {
916
    #[inline(always)]
917
    fn into_steelval(self) -> Result<SteelVal, SteelErr> {
15,015✔
918
        Ok(SteelVal::BoolV(self))
15,015✔
919
    }
920
}
921

922
impl From<Vector<SteelVal>> for SteelVal {
923
    #[inline(always)]
924
    fn from(val: Vector<SteelVal>) -> SteelVal {
24✔
925
        SteelVal::VectorV(Gc::new(val).into())
48✔
926
    }
927
}
928

929
impl From<FunctionSignature> for SteelVal {
930
    fn from(val: FunctionSignature) -> SteelVal {
×
931
        SteelVal::FuncV(val)
×
932
    }
933
}
934

935
#[cfg(test)]
936
mod try_from_tests {
937

938
    use super::*;
939

940
    #[test]
941
    fn from_char() {
942
        assert_eq!(SteelVal::from('c'), SteelVal::CharV('c'));
943
    }
944

945
    #[test]
946
    fn from_steelval_char() {
947
        assert_eq!(char::from_steelval(&SteelVal::CharV('c')).unwrap(), 'c')
948
    }
949

950
    #[test]
951
    fn into_steelval_char() {
952
        assert_eq!('c'.into_steelval().unwrap(), SteelVal::CharV('c'))
953
    }
954

955
    #[test]
956
    fn from_steelval_usize() {
957
        assert_eq!(usize::from_steelval(&SteelVal::IntV(10)).unwrap(), 10)
958
    }
959

960
    #[test]
961
    fn from_steelval_i32() {
962
        assert_eq!(i32::from_steelval(&SteelVal::IntV(32)).unwrap(), 32)
963
    }
964

965
    #[test]
966
    fn into_steelval_i32() {
967
        assert_eq!(32.into_steelval().unwrap(), SteelVal::IntV(32))
968
    }
969

970
    #[test]
971
    fn from_bool() {
972
        assert_eq!(SteelVal::from(true), SteelVal::BoolV(true));
973
    }
974

975
    #[test]
976
    fn try_from_steelval_string() {
977
        let expected = "foo".to_string();
978
        let input = SteelVal::StringV("foo".into());
979

980
        let res = String::try_from(input);
981
        assert_eq!(res.unwrap(), expected);
982
    }
983

984
    #[test]
985
    fn try_from_steelval_ref_string() {
986
        let expected = "foo".to_string();
987
        let input = SteelVal::StringV("foo".into());
988

989
        let res = String::try_from(&input);
990
        assert_eq!(res.unwrap(), expected);
991
    }
992
}
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