Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 73d80c5

Browse files
committed
Add constructor for integer values
1 parent 5aaac4d commit 73d80c5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

liblumen_alloc/src/erts/term.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,20 @@ pub fn make_tuple_from_slice(
242242
Ok(unsafe { Term::from_raw(tuple_ptr as usize | Term::FLAG_BOXED) })
243243
}
244244

245+
/// Constructs an integer value from any type that implements `Into<Integer>`,
246+
/// which currently includes `SmallInteger`, `BigInteger`, `usize` and `isize`.
247+
///
248+
/// This operation will transparently handle constructing the correct type of term
249+
/// based on the input value, i.e. an immediate small integer for values that fit,
250+
/// else a heap-allocated big integer for larger values.
251+
#[inline]
252+
pub fn make_integer<I: Into<Integer>>(process: &mut ProcessControlBlock, i: I) -> Term {
253+
match i.into() {
254+
Integer::Small(small) => small.as_term(),
255+
Integer::Big(big) => big.clone_to_process(process),
256+
}
257+
}
258+
245259
/// This function determines if the inner term of a boxed term contains a move marker
246260
///
247261
/// The value `term` should be the result of unboxing a boxed term:

0 commit comments

Comments
 (0)