perlmod/perlmod-test/src/magic.rs
Wolfgang Bumiller 1e46bfbe81 perlmod: magically call Drop handlers
magic classes now don't need to manually implement DESTROY
anymore

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-10-28 09:01:32 +02:00

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(())
}
}