Created
June 23, 2020 18:27
-
-
Save sakex/be7622d332e08c66de64007d03dfb3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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