diff --git a/kadmin/src/python.rs b/kadmin/src/python.rs index a7a032f..ba0e6f0 100644 --- a/kadmin/src/python.rs +++ b/kadmin/src/python.rs @@ -42,7 +42,7 @@ pub mod pykadmin { policy::Policy as KPolicy, principal::Principal as KPrincipal, sync::{KAdmin as KKAdmin, KAdminBuilder}, - tl_data::{TlData as KTlData, TlDataEntry as KTlDataEntry}, + tl_data::{TlData, TlDataEntry}, }; type Result = std::result::Result; @@ -50,6 +50,8 @@ pub mod pykadmin { #[pymodule_init] fn init(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add("__version__", env!("CARGO_PKG_VERSION"))?; + m.add_class::()?; + m.add_class::()?; Ok(()) } @@ -163,71 +165,6 @@ pub mod pykadmin { } } - /// A single TL-data entry - #[pyclass] - #[derive(Clone, Debug, Default)] - #[allow(clippy::exhaustive_structs)] - pub struct TlDataEntry { - /// TL-data type - /// - /// :type: int - #[pyo3(get, set)] - pub data_type: i16, - /// Entry contents - /// - /// :type: list[int] - #[pyo3(get, set)] - pub contents: Vec, - } - - impl From for TlDataEntry { - fn from(item: KTlDataEntry) -> Self { - Self { - data_type: item.data_type, - contents: item.contents, - } - } - } - - #[allow(clippy::from_over_into)] - impl Into for TlDataEntry { - fn into(self) -> KTlDataEntry { - KTlDataEntry { - data_type: self.data_type, - contents: self.contents, - } - } - } - - /// TL-data entries - #[pyclass] - #[derive(Clone, Debug, Default)] - #[allow(clippy::exhaustive_structs)] - pub struct TlData { - /// TL-data entries - /// - /// :type: list[TlDataEntry] - #[pyo3(get, set)] - pub entries: Vec, - } - - impl From for TlData { - fn from(item: KTlData) -> Self { - Self { - entries: item.entries.into_iter().map(|e| e.into()).collect(), - } - } - } - - #[allow(clippy::from_over_into)] - impl Into for TlData { - fn into(self) -> KTlData { - KTlData { - entries: self.entries.into_iter().map(|e| e.into()).collect(), - } - } - } - /// Interface to kadm5 /// /// This class has no constructor. Instead, use the `with_` methods diff --git a/kadmin/src/tl_data.rs b/kadmin/src/tl_data.rs index 382afb1..408b19b 100644 --- a/kadmin/src/tl_data.rs +++ b/kadmin/src/tl_data.rs @@ -3,10 +3,13 @@ use std::ptr::null_mut; use kadmin_sys::*; +#[cfg(feature = "python")] +use pyo3::prelude::*; /// A single TL-data entry -#[derive(Clone, Debug)] #[allow(clippy::exhaustive_structs)] +#[derive(Clone, Debug)] +#[cfg_attr(feature = "python", pyclass(get_all, set_all))] pub struct TlDataEntry { /// TL-data type pub data_type: i16, @@ -17,6 +20,7 @@ pub struct TlDataEntry { /// TL-data entries #[derive(Clone, Debug, Default)] #[allow(clippy::exhaustive_structs)] +#[cfg_attr(feature = "python", pyclass(get_all, set_all))] pub struct TlData { /// TL-data entries pub entries: Vec,