use crate::serde::Error;
use crate::{types::atom::Atom, Encoder, Env, Term};
atoms! {
nil,
ok,
error,
true_ = "true",
false_ = "false",
undefined,
nan,
inf,
neg_inf,
__struct__,
}
pub fn str_to_term<'a>(env: Env<'a>, string: &str) -> Term<'a> {
match Atom::existing_from_str(env, string) {
Ok(term) => term.encode(env),
Err(_) => string.encode(env),
}
}
pub fn term_to_string(term: &Term) -> Result<String, Error> {
if term.is_atom() {
term.atom_to_string().or(Err(Error::InvalidAtom))
} else {
Err(Error::InvalidStringable)
}
}