mirror of
git://git.proxmox.com/git/perlmod.git
synced 2025-01-19 18:03:36 +03:00
allow constants for class names in destructor macro
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
89989b0f56
commit
144831b5ae
@ -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 }
|
||||
}
|
||||
|
@ -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")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user