From ddf1700d5ba2363276ada1669670e188e7d38419 Mon Sep 17 00:00:00 2001 From: JoJo Date: Sun, 12 Mar 2023 12:24:08 +0100 Subject: [PATCH] impl From for Lisp for i64, &str, Option --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b0c8f26..da615dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,6 +236,28 @@ impl Lisp { } } +impl From for Lisp { + fn from(x: i64) -> Lisp { + Lisp::Int(x) + } +} +impl From<&str> for Lisp { + fn from(s: &str) -> Lisp { + Lisp::String(s.to_owned()) + } +} +impl From> for Lisp +where + Lisp: From, +{ + fn from(x: Option) -> Lisp { + match x { + Some(x) => Lisp::List(vec![Lisp::Symbol(Symbol::pack_str("some").unwrap()), Lisp::from(x)]), + None => Lisp::Symbol(Symbol::pack_str("none").unwrap()), + } + } +} + impl PartialEq for Lisp { fn eq(&self, rhs: &i64) -> bool { match self { -- 2.45.2