rune/core/object/
integer.rs
1use super::{CloneIn, IntoObject};
2use crate::core::gc::{Block, GcHeap, GcState, Trace};
3use crate::derive_GcMoveable;
4use num_bigint::BigInt;
5use std::fmt::Display;
6use std::ops::Deref;
7
8#[derive(PartialEq, Eq)]
9pub(crate) struct LispBigInt(GcHeap<BigInt>);
10
11derive_GcMoveable!(LispBigInt);
12
13impl<'new> CloneIn<'new, &'new Self> for LispBigInt {
14 fn clone_in<const C: bool>(&self, bk: &'new Block<C>) -> super::Gc<&'new Self> {
15 let big_int = self.0.clone();
16 big_int.into_obj(bk)
17 }
18}
19
20impl LispBigInt {
21 pub fn new(big_int: BigInt, constant: bool) -> Self {
22 LispBigInt(GcHeap::new(big_int, constant))
23 }
24}
25
26impl Display for LispBigInt {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28 write!(f, "{}", self.0)
29 }
30}
31
32impl Deref for LispBigInt {
33 type Target = BigInt;
34
35 fn deref(&self) -> &Self::Target {
36 &self.0
37 }
38}
39
40impl Trace for LispBigInt {
41 fn trace(&self, _: &mut GcState) {}
42}