Skip to content

Commit

Permalink
remove duplicated tl_data
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
  • Loading branch information
rissson committed Dec 1, 2024
1 parent 42860ad commit 09c8ae2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 67 deletions.
69 changes: 3 additions & 66 deletions kadmin/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ 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<T> = std::result::Result<T, exceptions::PyKAdminError>;

#[pymodule_init]
fn init(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
m.add_class::<TlDataEntry>()?;
m.add_class::<TlData>()?;
Ok(())
}

Expand Down Expand Up @@ -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<u8>,
}

impl From<KTlDataEntry> for TlDataEntry {
fn from(item: KTlDataEntry) -> Self {
Self {
data_type: item.data_type,
contents: item.contents,
}
}
}

#[allow(clippy::from_over_into)]
impl Into<KTlDataEntry> 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<TlDataEntry>,
}

impl From<KTlData> 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<KTlData> 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
Expand Down
6 changes: 5 additions & 1 deletion kadmin/src/tl_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<TlDataEntry>,
Expand Down

0 comments on commit 09c8ae2

Please sign in to comment.