/ cab / runtime / value / integer.rs
integer.rs
 1  use std::sync::Arc;
 2  
 3  use dup::Dupe;
 4  use ust::{
 5     style::StyledExt as _,
 6     terminal::tag,
 7  };
 8  
 9  use crate::{
10     Value,
11     value,
12  };
13  
14  #[derive(Clone, Dupe)]
15  pub struct Integer(Arc<num::BigInt>);
16  
17  impl tag::DisplayTags for Integer {
18     fn display_tags<'a>(&'a self, tags: &mut tag::Tags<'a>) {
19        tags.write(self.0.to_string().cyan().bold());
20     }
21  }
22  
23  impl From<num::BigInt> for Integer {
24     fn from(integer: num::BigInt) -> Self {
25        Self(Arc::new(integer))
26     }
27  }
28  
29  // FIXME: Incredibly sloppy code. Also, negatives? Lol, lmao even.
30  impl From<Integer> for value::Attributes {
31     fn from(val: Integer) -> Self {
32        let mut number = (*val.0).clone();
33  
34        // TODO: Better zero and succ.
35        let mut attributes =
36           value::attributes::new! { "__zero__": Value::from(value::attributes::new! {}) };
37  
38        while number != 0_u32.into() {
39           attributes = value::attributes::new! { "__succ__": Value::from(attributes) };
40           number -= 1_u32;
41        }
42  
43        attributes
44     }
45  }
46  
47  impl TryFrom<value::Attributes> for Integer {
48     type Error = ();
49  
50     fn try_from(_attributes: value::Attributes) -> Result<Self, Self::Error> {
51        todo!()
52     }
53  }