forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraverse_object.rs
More file actions
34 lines (29 loc) · 992 Bytes
/
traverse_object.rs
File metadata and controls
34 lines (29 loc) · 992 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 std::fmt;
use crate::PyObject;
use super::core::{InstanceDict, debug_obj, drop_dealloc_obj, try_trace_obj};
use super::{PyObjectPayload, Traverse, TraverseFn};
pub(in crate::object) struct PyObjVTable {
pub(in crate::object) drop_dealloc: unsafe fn(*mut PyObject),
pub(in crate::object) debug: unsafe fn(&PyObject, &mut fmt::Formatter<'_>) -> fmt::Result,
pub(in crate::object) trace: Option<unsafe fn(&PyObject, &mut TraverseFn<'_>)>,
}
impl PyObjVTable {
pub const fn of<T: PyObjectPayload>() -> &'static Self {
&PyObjVTable {
drop_dealloc: drop_dealloc_obj::<T>,
debug: debug_obj::<T>,
trace: const {
if T::IS_TRACE {
Some(try_trace_obj::<T>)
} else {
None
}
},
}
}
}
unsafe impl Traverse for InstanceDict {
fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) {
self.d.traverse(tracer_fn)
}
}