Merge pull request #4651 from minhrongcon2000/fix/add-arg-index

Add ArgIndex according to #4629
This commit is contained in:
Jeong YunWon
2023-03-07 15:19:38 +09:00
committed by GitHub

View File

@@ -1,4 +1,4 @@
use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
use crate::{builtins::PyIntRef, AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
use num_complex::Complex64;
use std::ops::Deref;
@@ -125,3 +125,32 @@ impl TryFromObject for ArgIntoBool {
})
}
}
// Implement ArgIndex to seperate between "true" int and int generated by index
#[derive(Debug)]
#[repr(transparent)]
pub struct ArgIndex {
value: PyIntRef,
}
impl From<ArgIndex> for PyIntRef {
fn from(arg: ArgIndex) -> Self {
arg.value
}
}
impl Deref for ArgIndex {
type Target = PyIntRef;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl TryFromObject for ArgIndex {
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
Ok(Self {
value: obj.try_index(vm)?,
})
}
}