introduce ArgSize

This commit is contained in:
Jeong YunWon
2023-03-10 06:07:25 +09:00
parent ed7bcf787c
commit e95529aca0
2 changed files with 29 additions and 1 deletions

View File

@@ -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};

View File

@@ -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)?,
})
}
}