pyclass member support for #[pymodule]

This commit is contained in:
Jeong YunWon
2020-03-29 18:27:10 +09:00
parent 7cea2c3953
commit 06f8d0bb98
4 changed files with 119 additions and 91 deletions

View File

@@ -9,7 +9,7 @@
* https://docs.rs/byteorder/1.2.6/byteorder/
*/
use crate::pyobject::{PyClassImpl, PyObjectRef};
use crate::pyobject::PyObjectRef;
use crate::VirtualMachine;
#[pymodule]
@@ -26,7 +26,9 @@ mod _struct {
objbool::IntoPyBool, objbytes::PyBytesRef, objstr::PyString, objstr::PyStringRef,
objtuple::PyTuple, objtype::PyClassRef,
};
use crate::pyobject::{Either, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject};
use crate::pyobject::{
Either, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
};
use crate::VirtualMachine;
#[derive(Debug)]
@@ -663,7 +665,7 @@ mod _struct {
#[pyclass(name = "Struct")]
#[derive(Debug)]
pub(crate) struct PyStruct {
struct PyStruct {
spec: FormatSpec,
fmt_str: PyStringRef,
}
@@ -695,6 +697,7 @@ mod _struct {
fn format(&self) -> PyStringRef {
self.fmt_str.clone()
}
#[pyproperty]
fn size(&self) -> usize {
self.spec.size()
@@ -730,7 +733,6 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let module = _struct::make_module(vm);
extend_module!(vm, module, {
"error" => struct_error,
"Struct" => _struct::PyStruct::make_class(ctx),
});
module
}