From 03644975f4900fcebefde0fc1f3ac0c9e50f80fe Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 16 Feb 2021 10:39:01 +0100 Subject: [PATCH] use try_from_ref in the example to show how it's used Signed-off-by: Wolfgang Bumiller --- perlmod-test/src/bless.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/perlmod-test/src/bless.rs b/perlmod-test/src/bless.rs index f609957..310393c 100644 --- a/perlmod-test/src/bless.rs +++ b/perlmod-test/src/bless.rs @@ -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)? }) + } } }