artichoke_backend/extn/core/symbol/
mod.rs1use std::ffi::c_void;
2
3use crate::convert::{Immediate, UnboxedValueGuard};
4use crate::extn::prelude::*;
5
6pub mod ffi;
7pub(in crate::extn) mod mruby;
8pub(super) mod trampoline;
9
10#[doc(inline)]
11pub use spinoso_symbol::Symbol;
12
13impl BoxUnboxVmValue for Symbol {
14 type Unboxed = Self;
15 type Guarded = Immediate<Self::Unboxed>;
16
17 const RUBY_TYPE: &'static str = "Symbol";
18
19 unsafe fn unbox_from_value<'a>(
20 value: &'a mut Value,
21 interp: &mut Artichoke,
22 ) -> Result<UnboxedValueGuard<'a, Self::Guarded>, Error> {
23 let _ = interp;
24
25 if value.ruby_type() != Ruby::Symbol {
28 let mut message = String::from("uninitialized ");
29 message.push_str(Self::RUBY_TYPE);
30 return Err(TypeError::from(message).into());
31 }
32
33 let value = value.inner();
34 let symbol_id = value.value.sym;
37 Ok(UnboxedValueGuard::new(Immediate::new(symbol_id.into())))
38 }
39
40 fn alloc_value(value: Self::Unboxed, interp: &mut Artichoke) -> Result<Value, Error> {
41 let _ = interp;
42
43 let symbol_id = u32::from(value);
44 let obj = unsafe { sys::mrb_sys_new_symbol(symbol_id) };
45 Ok(Value::from(obj))
46 }
47
48 fn box_into_value(value: Self::Unboxed, into: Value, interp: &mut Artichoke) -> Result<Value, Error> {
49 let _ = value;
50 let _ = into;
51 let _ = interp;
52 Err(Fatal::from("Symbols are immutable and cannot be reinitialized").into())
53 }
54
55 fn free(data: *mut c_void) {
56 let _ = data;
59 }
60}