-
Notifications
You must be signed in to change notification settings - Fork 2
/
entitlement.rs
38 lines (34 loc) · 975 Bytes
/
entitlement.rs
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
35
36
37
38
use chrono::{DateTime, Utc};
use pyo3::prelude::{PyAnyMethods, PyModule, PyModuleMethods};
use pyo3::{pyclass, pymodule, Bound, PyResult, Python};
#[pymodule(name = "entitlement")]
pub fn entitlement_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
// Hack: workaround for https://github.com/PyO3/pyo3/issues/759
Python::with_gil(|py| {
py.import("sys")?
.getattr("modules")?
.set_item("keygen_sh.entitlement", m)
})?;
m.add_class::<Entitlement>()?;
Ok(())
}
#[pyclass(frozen)]
#[derive(Debug, Clone)]
pub struct Entitlement {
pub id: String,
pub name: Option<String>,
pub code: String,
pub created: DateTime<Utc>,
pub updated: DateTime<Utc>,
}
impl Entitlement {
pub(crate) fn build(
id: String,
name: Option<String>,
code: String,
created: DateTime<Utc>,
updated: DateTime<Utc>,
) -> Self {
Self { id, name, code, created, updated }
}
}