Skip to content

Commit db7b945

Browse files
Add ArgIndex according to RustPython#4629
1 parent 4d464cc commit db7b945

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

vm/src/function/number.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
2+
use num_bigint::BigInt;
23
use num_complex::Complex64;
34
use std::ops::Deref;
45

@@ -125,3 +126,32 @@ impl TryFromObject for ArgIntoBool {
125126
})
126127
}
127128
}
129+
130+
// Implement ArgIndex to seperate between "true" int and int generated by index
131+
#[derive(Debug, PartialEq)]
132+
#[repr(transparent)]
133+
pub struct ArgIndex {
134+
value: BigInt,
135+
}
136+
137+
impl From<ArgIndex> for BigInt {
138+
fn from(arg: ArgIndex) -> Self {
139+
arg.value
140+
}
141+
}
142+
143+
impl Deref for ArgIndex {
144+
type Target = BigInt;
145+
146+
fn deref(&self) -> &Self::Target {
147+
&self.value
148+
}
149+
}
150+
151+
impl TryFromObject for ArgIndex {
152+
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
153+
Ok(Self {
154+
value: obj.try_index(vm)?.as_bigint().clone(),
155+
})
156+
}
157+
}

0 commit comments

Comments
 (0)