forked from Rust-related/RustPython
introduce ArgSize
This commit is contained in:
@@ -17,7 +17,7 @@ pub use builtin::{IntoPyNativeFunc, OwnedParam, PyNativeFunc, RefParam};
|
||||
pub use either::Either;
|
||||
pub use getset::PySetterValue;
|
||||
pub(super) use getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc};
|
||||
pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat};
|
||||
pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat, ArgSize};
|
||||
pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence};
|
||||
|
||||
use crate::{builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyResult, VirtualMachine};
|
||||
|
||||
@@ -154,3 +154,31 @@ impl TryFromObject for ArgIndex {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(transparent)]
|
||||
pub struct ArgSize {
|
||||
value: isize,
|
||||
}
|
||||
|
||||
impl From<ArgSize> for isize {
|
||||
fn from(arg: ArgSize) -> Self {
|
||||
arg.value
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ArgSize {
|
||||
type Target = isize;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromObject for ArgSize {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
value: obj.try_index(vm)?.try_to_primitive(vm)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user