1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::convert::implicitly_convert_to_int;
use crate::extn::core::integer::Integer;
use crate::extn::prelude::*;

pub fn chr(interp: &mut Artichoke, value: Value, encoding: Option<Value>) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let s = value.chr(interp, encoding)?;
    Ok(interp.convert_mut(s))
}

pub fn element_reference(interp: &mut Artichoke, value: Value, bit: Value) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let bit = implicitly_convert_to_int(interp, bit)?;
    let bit = value.bit(bit)?;
    Ok(interp.convert(bit))
}

pub fn div(interp: &mut Artichoke, value: Value, denominator: Value) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let quotient = value.div(interp, denominator)?;
    Ok(interp.convert_mut(quotient))
}

pub fn is_allbits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_allbits(mask);
    Ok(interp.convert(result))
}

pub fn is_anybits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_anybits(mask);
    Ok(interp.convert(result))
}

pub fn is_nobits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_nobits(mask);
    Ok(interp.convert(result))
}

pub fn size(interp: &Artichoke) -> Result<Value, Error> {
    // This `as` cast is lossless because size_of::<Int> is guaranteed to be
    // less than `Int::MAX`.
    let size = Integer::size() as Int;
    Ok(interp.convert(size))
}