Skip to content

Instantly share code, notes, and snippets.

@sakex
Created June 23, 2020 18:27
Show Gist options
  • Save sakex/be7622d332e08c66de64007d03dfb3b8 to your computer and use it in GitHub Desktop.
Save sakex/be7622d332e08c66de64007d03dfb3b8 to your computer and use it in GitHub Desktop.
// src/engine.rs
use std::ffi::c_void;
use crate::bindings::engine_factory;
pub struct Engine {
ptr: *mut c_void
}
impl Engine {
pub fn new() -> Engine {
unsafe {
Engine {
ptr: engine_factory()
}
}
}
}
impl Drop for Engine {
// RAII (free the memory when the Engine struct goes out of scope)
fn drop(&mut self) {
unsafe {libc::free(self.ptr);}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment