diff --git a/perlmod-test/src/bless.rs b/perlmod-test/src/bless.rs index 0cf96ec..6d1a6f9 100644 --- a/perlmod-test/src/bless.rs +++ b/perlmod-test/src/bless.rs @@ -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::("RSPM::Bless")? }; + let this = unsafe { this.from_blessed_box::(CLASSNAME)? }; println!("Called something on Bless {{ {:?} }}!", this.content); Ok(()) } - perlmod::destructor! { Bless : "RSPM::Bless" } + perlmod::destructor! { Bless : CLASSNAME } } diff --git a/perlmod/src/macros.rs b/perlmod/src/macros.rs index dcee84c..a8dae33 100644 --- a/perlmod/src/macros.rs +++ b/perlmod/src/macros.rs @@ -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")]