artichoke_backend/extn/core/symbol/
mod.rsuse std::ffi::c_void;
use crate::convert::{Immediate, UnboxedValueGuard};
use crate::extn::prelude::*;
pub mod ffi;
pub(in crate::extn) mod mruby;
pub(super) mod trampoline;
#[doc(inline)]
pub use spinoso_symbol::Symbol;
impl BoxUnboxVmValue for Symbol {
type Unboxed = Self;
type Guarded = Immediate<Self::Unboxed>;
const RUBY_TYPE: &'static str = "Symbol";
unsafe fn unbox_from_value<'a>(
value: &'a mut Value,
interp: &mut Artichoke,
) -> Result<UnboxedValueGuard<'a, Self::Guarded>, Error> {
let _ = interp;
if value.ruby_type() != Ruby::Symbol {
let mut message = String::from("uninitialized ");
message.push_str(Self::RUBY_TYPE);
return Err(TypeError::from(message).into());
}
let value = value.inner();
let symbol_id = value.value.sym;
Ok(UnboxedValueGuard::new(Immediate::new(symbol_id.into())))
}
fn alloc_value(value: Self::Unboxed, interp: &mut Artichoke) -> Result<Value, Error> {
let _ = interp;
let symbol_id = u32::from(value);
let obj = unsafe { sys::mrb_sys_new_symbol(symbol_id) };
Ok(Value::from(obj))
}
fn box_into_value(value: Self::Unboxed, into: Value, interp: &mut Artichoke) -> Result<Value, Error> {
let _ = value;
let _ = into;
let _ = interp;
Err(Fatal::from("Symbols are immutable and cannot be reinitialized").into())
}
fn free(data: *mut c_void) {
let _ = data;
}
}