mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Add ArgIndex according to #4629
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
|
||||
use num_bigint::BigInt;
|
||||
use num_complex::Complex64;
|
||||
use std::ops::Deref;
|
||||
|
||||
@@ -125,3 +126,32 @@ impl TryFromObject for ArgIntoBool {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Implement ArgIndex to seperate between "true" int and int generated by index
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[repr(transparent)]
|
||||
pub struct ArgIndex {
|
||||
value: BigInt,
|
||||
}
|
||||
|
||||
impl From<ArgIndex> for BigInt {
|
||||
fn from(arg: ArgIndex) -> Self {
|
||||
arg.value
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ArgIndex {
|
||||
type Target = BigInt;
|
||||
|
||||
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)?.as_bigint().clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user