Fix pyo3 cfg_attr+new nosense

This commit is contained in:
Andrea Fioraldi 2021-09-29 18:07:57 +02:00
parent 5a722994ac
commit 5a246175cf

View File

@ -38,7 +38,6 @@ impl IntoPy<PyObject> for MmapPerms {
}
#[repr(C)]
#[cfg(feature = "python")]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", derive(FromPyObject))]
pub struct SyscallHookResult {
@ -46,9 +45,27 @@ pub struct SyscallHookResult {
pub skip_syscall: bool,
}
#[cfg_attr(feature = "python", pymethods)]
#[cfg(feature = "python")]
#[pymethods]
impl SyscallHookResult {
#[new]
#[must_use]
pub fn new(value: Option<u64>) -> Self {
value.map_or(
Self {
retval: 0,
skip_syscall: false,
},
|v| Self {
retval: v,
skip_syscall: true,
},
)
}
}
#[cfg(not(feature = "python"))]
impl SyscallHookResult {
#[cfg_attr(feature = "python", new)]
#[must_use]
pub fn new(value: Option<u64>) -> Self {
value.map_or(