Skip to content

Commit

Permalink
fix: change export attr, improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
HoloTheDrunk committed May 20, 2024
1 parent d53816a commit 4e98260
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/rune-macros/src/item_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ItemImpl {
let Self(mut block) = self;

let mut export_list = Vec::new();
let export_attr: syn::Attribute = syn::parse_quote!(#[export]);
let export_attr: syn::Attribute = syn::parse_quote!(#[rune(export)]);

for item in block.items.iter_mut() {
if let syn::ImplItem::Fn(method) = item {
Expand Down
29 changes: 23 additions & 6 deletions crates/rune-macros/tests/derive.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Debug;

use rune::T;
use rune_macros::*;

Expand Down Expand Up @@ -25,20 +27,20 @@ fn export_impl() {

#[crate::item_impl(exporter = export_rune_api)]
impl MyStruct {
#[export]
#[rune(export)]
pub fn foo(&self) -> usize {
self.0
}
}

#[crate::item_impl(list = rune_api_extension, exporter = export_rune_api_extension)]
impl MyStruct {
#[export]
#[rune(export)]
pub fn bar(&self) -> usize {
self.0 + 1
}

#[export]
#[rune(export)]
pub fn baz() -> usize {
42
}
Expand All @@ -59,7 +61,22 @@ fn export_impl() {
}
}

assert!(MyStruct(2).foo() + 1 == MyStruct(2).bar());
assert!(MyStruct::rune_export(rune::Module::new()).is_ok());
assert!(MyStruct::baz() == 42);
let a = MyStruct(2);
assert_eq!(a.foo() + 1, a.bar());

fn test_fn<F, T, E>(f: F)
where
E: Debug,
F: Fn(rune::Module) -> Result<T, E>,
{
let mut m = rune::Module::new();
m.ty::<MyStruct>().unwrap();
f(m).unwrap();
}

test_fn(MyStruct::rune_export);
test_fn(MyStruct::export_rune_api);
test_fn(MyStruct::export_rune_api_extension);

assert_eq!(MyStruct::baz(), 42);
}

0 comments on commit 4e98260

Please sign in to comment.