[pve-devel] [PATCH 1/1] pve-rs: add PVE::RS::CalendarEvent

Dominik Csapak d.csapak at proxmox.com
Wed Dec 1 09:55:13 CET 2021


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 pve-rs/Makefile              |  1 +
 pve-rs/src/calendar_event.rs | 20 ++++++++++++++++++++
 pve-rs/src/lib.rs            |  1 +
 3 files changed, 22 insertions(+)
 create mode 100644 pve-rs/src/calendar_event.rs

diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index c912d9d..0b53d4d 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -20,6 +20,7 @@ PM_DIRS := \
 
 PM_FILES := \
 	PVE/RS/APT/Repositories.pm \
+	PVE/RS/CalendarEvent.pm \
 	PVE/RS/OpenId.pm \
 	PVE/RS/TFA.pm
 
diff --git a/pve-rs/src/calendar_event.rs b/pve-rs/src/calendar_event.rs
new file mode 100644
index 0000000..b898b15
--- /dev/null
+++ b/pve-rs/src/calendar_event.rs
@@ -0,0 +1,20 @@
+#[perlmod::package(name = "${PERLMOD_PRODUCT}::RS::CalendarEvent")]
+mod export {
+    use anyhow::Error;
+    use perlmod::Value;
+
+    perlmod::declare_magic!(Box<CalendarEvent> : &CalendarEvent as "${PERLMOD_PRODUCT}::RS::CalendarEvent");
+
+    #[repr(transparent)]
+    struct CalendarEvent(proxmox_time::CalendarEvent);
+
+    #[export(raw_return)]
+    fn new(#[raw] class: Value, event: String) -> Result<Value, Error> {
+        Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(CalendarEvent(event.parse()?))))
+    }
+
+    #[export]
+    fn compute_next_event(#[try_from_ref] this: &CalendarEvent, last: i64) -> Result<Option<i64>, Error> {
+        this.0.compute_next_event(last)
+    }
+}
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index 594a96f..2c25ee1 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -5,3 +5,4 @@ pub mod apt;
 
 pub mod openid;
 pub mod tfa;
+pub mod calendar_event;
-- 
2.30.2






More information about the pve-devel mailing list