1use crate::{Env, Result, Value, global::{GlobalRef, OnceGlobalRef}};
2
3#[macro_export]
16macro_rules! use_symbols {
17 ($( $name:ident $( => $lisp_name:expr )? )*) => {
18 $crate::global_refs! {__emrs_init_global_refs_to_symbols__(init_to_symbol) =>
19 $( $name $( => $lisp_name )? )*
20 }
21 }
22}
23
24use_symbols! {
25 nil t
26 error
27 rust_error
28 rust_panic
29 rust_wrong_type_user_ptr
30}
31
32pub trait IntoLispSymbol<'e> {
33 fn into_lisp_symbol(self, env: &'e Env) -> Result<Value<'e>>;
34}
35
36impl<'e> IntoLispSymbol<'e> for Value<'e> {
37 #[inline(always)]
38 fn into_lisp_symbol(self, _: &'e Env) -> Result<Value<'e>> {
39 Ok(self)
40 }
41}
42
43impl<'e, T: AsRef<str>> IntoLispSymbol<'e> for T {
44 #[inline(always)]
45 fn into_lisp_symbol(self, env: &'e Env) -> Result<Value<'e>> {
46 env.intern(self.as_ref())
47 }
48}
49
50impl<'e> IntoLispSymbol<'e> for &'e GlobalRef {
51 #[inline(always)]
52 fn into_lisp_symbol(self, env: &'e Env) -> Result<Value<'e>> {
53 self.bind(env).into_lisp_symbol(env)
54 }
55}
56
57impl<'e> IntoLispSymbol<'e> for &'e OnceGlobalRef {
58 #[inline(always)]
59 fn into_lisp_symbol(self, env: &'e Env) -> Result<Value<'e>> {
60 self.bind(env).into_lisp_symbol(env)
61 }
62}