allow constants for class names in destructor macro

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-11-26 11:57:28 +01:00
parent 89989b0f56
commit 144831b5ae
2 changed files with 10 additions and 7 deletions

View File

@ -4,6 +4,8 @@ mod export {
use perlmod::Value;
const CLASSNAME: &str = "RSPM::Bless";
struct Bless {
content: String,
}
@ -22,10 +24,10 @@ mod export {
#[export]
fn something(#[raw] this: Value) -> Result<(), Error> {
let this = unsafe { this.from_blessed_box::<Bless>("RSPM::Bless")? };
let this = unsafe { this.from_blessed_box::<Bless>(CLASSNAME)? };
println!("Called something on Bless {{ {:?} }}!", this.content);
Ok(())
}
perlmod::destructor! { Bless : "RSPM::Bless" }
perlmod::destructor! { Bless : CLASSNAME }
}

View File

@ -10,7 +10,7 @@
/// Usage:
/// ```ignore
/// // complete:
/// destructor!(MyType : "My::RS::Package" {
/// destructor!(MyType : "My::RS::Package" => {
/// Err(err) => { eprintln!("DESTROY called with invalid pointer: {}", err); }
/// });
///
@ -20,7 +20,8 @@
/// });
///
/// // simple case with default error case (which is the above example case)
/// destructor!(MyType : "My::RS::Package");
/// // the class name can also reference a constant.
/// destructor!(MyType : CLASSNAME);
///
/// // simple less-safe case without checking the reference type.
/// destructor!(MyType);
@ -44,9 +45,9 @@
/// ```
#[macro_export]
macro_rules! destructor {
($ty:ty : $package:literal) => {
($ty:ty : $package:expr) => {
$crate::destructor! {
$ty : $package {
$ty : $package => {
Err(err) => {
eprintln!("DESTROY called with invalid pointer: {}", err);
}
@ -54,7 +55,7 @@ macro_rules! destructor {
}
};
($ty:ty : $package:literal {
($ty:ty : $package:expr => {
Err($errname:ident) => $on_err:expr
}) => {
#[perlmod::export(name = "DESTROY")]