]>
Witch of Git - mukan/blob - src/term.rs
1 use std
::{fmt
, sync
::Arc
};
3 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
4 pub struct Var(pub(crate) u32);
6 #[derive(Clone, PartialEq, Eq)]
9 Pair(Arc
<Term
>, Arc
<Term
>),
13 impl From
<&Term
> for Term
{
14 fn from(term
: &Term
) -> Term
{
19 impl From
<i32> for Term
{
20 fn from(i
: i32) -> Term
{
25 impl From
<Var
> for Term
{
26 fn from(var
: Var
) -> Term
{
31 impl<T
, U
> From
<(T
, U
)> for Term
36 fn from((t
, u
): (T
, U
)) -> Term
{
37 Term
::Pair(Arc
::new(t
.into
()), Arc
::new(u
.into
()))
41 impl fmt
::Display
for Term
{
42 fn fmt(&self, fmt
: &mut fmt
::Formatter
) -> fmt
::Result
{
44 Term
::Var(v
) => write
!(fmt
, "{:?}", v
),
45 Term
::Pair(l
, r
) => write
!(fmt
, "({}, {})", *l
, *r
),
46 Term
::Lit(i
) => write
!(fmt
, "{}", i
),
51 impl fmt
::Debug
for Term
{
52 fn fmt(&self, fmt
: &mut fmt
::Formatter
) -> fmt
::Result
{
53 write
!(fmt
, "{}", self)
57 impl fmt
::Debug
for Var
{
58 fn fmt(&self, fmt
: &mut fmt
::Formatter
) -> fmt
::Result
{
59 write
!(fmt
, "x{}", self.0)