artichoke_backend/extn/core/integer/
trampoline.rs

1use crate::convert::implicitly_convert_to_int;
2use crate::extn::core::integer::Integer;
3use crate::extn::prelude::*;
4
5pub fn chr(interp: &mut Artichoke, value: Value, encoding: Option<Value>) -> Result<Value, Error> {
6    let value = value.try_convert_into::<Integer>(interp)?;
7    let s = value.chr(interp, encoding)?;
8    spinoso_string::String::alloc_value(s, interp)
9}
10
11pub fn element_reference(interp: &mut Artichoke, value: Value, bit: Value) -> Result<Value, Error> {
12    let value = value.try_convert_into::<Integer>(interp)?;
13    let bit = implicitly_convert_to_int(interp, bit)?;
14    let bit = value.bit(bit);
15    Ok(interp.convert(bit))
16}
17
18pub fn div(interp: &mut Artichoke, value: Value, denominator: Value) -> Result<Value, Error> {
19    let value = value.try_convert_into::<Integer>(interp)?;
20    let quotient = value.div(interp, denominator)?;
21    Ok(interp.convert_mut(quotient))
22}
23
24pub fn is_allbits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
25    let value = value.try_convert_into::<Integer>(interp)?;
26    let mask = implicitly_convert_to_int(interp, mask)?;
27    let result = value.is_allbits(mask);
28    Ok(interp.convert(result))
29}
30
31pub fn is_anybits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
32    let value = value.try_convert_into::<Integer>(interp)?;
33    let mask = implicitly_convert_to_int(interp, mask)?;
34    let result = value.is_anybits(mask);
35    Ok(interp.convert(result))
36}
37
38pub fn is_nobits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
39    let value = value.try_convert_into::<Integer>(interp)?;
40    let mask = implicitly_convert_to_int(interp, mask)?;
41    let result = value.is_nobits(mask);
42    Ok(interp.convert(result))
43}
44
45#[expect(clippy::cast_possible_wrap, reason = "const assert ensures wrapping is impossible")]
46#[expect(
47    clippy::unnecessary_wraps,
48    reason = "all trampoline functions should be fallible for consistency. This method will become fallible once `Bignum` is implemented."
49)]
50pub fn size(interp: &Artichoke) -> Result<Value, Error> {
51    qed::const_assert!(Integer::size() < i8::MAX as usize);
52    Ok(interp.convert(const { Integer::size() as i64 }))
53}