forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjmemory.rs
More file actions
34 lines (30 loc) · 874 Bytes
/
objmemory.rs
File metadata and controls
34 lines (30 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::function::PyFuncArgs;
use crate::pyobject::{PyContext, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol};
use crate::vm::VirtualMachine;
#[derive(Debug)]
pub struct PyMemoryView {
obj: PyObjectRef,
}
impl PyValue for PyMemoryView {
fn class(vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.memoryview_type()
}
}
pub fn new_memory_view(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(cls, None), (bytes_object, None)]);
vm.ctx.set_attr(&cls, "obj", bytes_object.clone());
Ok(PyObject::new(
PyMemoryView {
obj: bytes_object.clone(),
},
cls.clone(),
))
}
pub fn init(ctx: &PyContext) {
let memoryview_type = &ctx.memoryview_type;
ctx.set_attr(
&memoryview_type,
"__new__",
ctx.new_rustfunc(new_memory_view),
);
}