mirror of
https://git.proxmox.com/git/perlmod
synced 2025-10-19 19:04:34 +00:00

magic classes now don't need to manually implement DESTROY anymore Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
28 lines
745 B
Rust
28 lines
745 B
Rust
#[perlmod::package(name = "RSPM::Magic", lib = "perlmod_test")]
|
|
mod export {
|
|
use perlmod::{Error, Value};
|
|
|
|
perlmod::declare_magic!(Box<Magic> : &Magic as "RSPM::Magic");
|
|
|
|
struct Magic {
|
|
content: String,
|
|
}
|
|
|
|
impl Drop for Magic {
|
|
fn drop(&mut self) {
|
|
println!("Dropping blessed magic with content {:?}", self.content);
|
|
}
|
|
}
|
|
|
|
#[export(raw_return)]
|
|
fn new(#[raw] class: Value, content: String) -> Result<Value, Error> {
|
|
Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(Magic { content })))
|
|
}
|
|
|
|
#[export]
|
|
fn call(#[try_from_ref] this: &Magic) -> Result<(), Error> {
|
|
println!("Calling magic with content {:?}", this.content);
|
|
Ok(())
|
|
}
|
|
}
|