]> git.proxmox.com Git - perlmod.git/commitdiff
use try_from_ref in the example
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 16 Feb 2021 09:39:01 +0000 (10:39 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 16 Feb 2021 09:39:02 +0000 (10:39 +0100)
to show how it's used

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
perlmod-test/src/bless.rs

index f6099572fb6bac45df2b127bcb522f6d10d56901..310393cdd1af9d7f0dd9001ce0d0cf5e43e4e59d 100644 (file)
@@ -1,5 +1,7 @@
 #[perlmod::package(name = "RSPM::Bless", lib = "perlmod_test")]
 mod export {
+    use std::convert::TryFrom;
+
     use anyhow::Error;
 
     use perlmod::Value;
@@ -29,8 +31,25 @@ mod export {
         Ok(())
     }
 
+    #[export]
+    fn another(#[try_from_ref] this: &Bless, param: u32) -> Result<(), Error> {
+        println!(
+            "Called 'another({})' on Bless {{ {:?} }}!",
+            param, this.content
+        );
+        Ok(())
+    }
+
     #[export(name = "DESTROY")]
     fn destroy(#[raw] this: Value) {
-        perlmod::destructor!(this, Bless : CLASSNAME);
+        perlmod::destructor!(this, Bless: CLASSNAME);
+    }
+
+    impl<'a> TryFrom<&'a Value> for &'a Bless {
+        type Error = Error;
+
+        fn try_from(value: &'a Value) -> Result<&'a Bless, Error> {
+            Ok(unsafe { value.from_blessed_box(CLASSNAME)? })
+        }
     }
 }