use crate::{symbol, Env, Value, Result};
pub use {user_ptr::Transfer, vector::Vector};
mod integer;
mod float;
mod string;
mod user_ptr;
mod vector;
pub trait FromLisp<'e>: Sized {
fn from_lisp(value: Value<'e>) -> Result<Self>;
}
pub trait IntoLisp<'e> {
fn into_lisp(self, env: &'e Env) -> Result<Value<'e>>;
}
impl<'e> FromLisp<'e> for Value<'e> {
#[inline(always)]
fn from_lisp(value: Value<'e>) -> Result<Value<'_>> {
Ok(value)
}
}
impl<'e> IntoLisp<'e> for Value<'e> {
#[inline(always)]
fn into_lisp(self, _: &'e Env) -> Result<Value<'_>> {
Ok(self)
}
}
impl<'e, T: FromLisp<'e>> FromLisp<'e> for Option<T> {
fn from_lisp(value: Value<'e>) -> Result<Self> {
if value.is_not_nil() {
Ok(Some(<T as FromLisp>::from_lisp(value)?))
} else {
Ok(None)
}
}
}
impl<'e, T: IntoLisp<'e>> IntoLisp<'e> for Option<T> {
fn into_lisp(self, env: &'e Env) -> Result<Value<'_>> {
match self {
Some(t) => t.into_lisp(env),
None => symbol::nil.into_lisp(env),
}
}
}
impl IntoLisp<'_> for () {
fn into_lisp(self, env: &Env) -> Result<Value<'_>> {
symbol::nil.into_lisp(env)
}
}
impl IntoLisp<'_> for bool {
fn into_lisp(self, env: &Env) -> Result<Value<'_>> {
if self {
symbol::t.into_lisp(env)
} else {
symbol::nil.into_lisp(env)
}
}
}