Skip to content

Commit

Permalink
Initializes Ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Oct 5, 2024
1 parent dc17eed commit 5a23aa1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion macros/src/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn render_class(item: Class) -> syn::Result<TokenStream> {
let name = format_ident!("new{}", i + 1, span = ctor.span);

ctors.extend(quote! {
pub unsafe fn #name() {}
pub unsafe fn #name() -> ::cppbind::Ptr<Self> {
todo!();
}
});
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
pub use cppbind_macros::*;

/// RAII struct to free a C++ object on the heap.
pub struct Ptr<T>(*mut T);

impl<T> Drop for Ptr<T> {
fn drop(&mut self) {
unsafe { std::ptr::drop_in_place(self.0) };
}
}

0 comments on commit 5a23aa1

Please sign in to comment.