introduce ArgSize

This commit is contained in:
Jeong YunWon committed 2023-03-10 06:21:39 +09:00
1 parent ed7bcf787c
commit e95529aca0
2 files changed
+29 -1

No files matched your search

+1 -1
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};
+28
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)?,
})
}
}