lix/nix-rust/src/lib.rs

25 lines
479 B
Rust
Raw Normal View History

2019-09-10 19:55:32 +00:00
mod error;
mod foreign;
2019-03-27 13:12:20 +00:00
2019-09-10 19:55:32 +00:00
pub use error::Error;
pub struct CBox<T> {
2019-09-11 10:44:31 +00:00
pub ptr: *mut libc::c_void,
phantom: std::marker::PhantomData<T>,
}
impl<T> CBox<T> {
fn new(t: T) -> Self {
unsafe {
let size = std::mem::size_of::<T>();
let ptr = libc::malloc(size);
*(ptr as *mut T) = t; // FIXME: probably UB
Self {
ptr,
phantom: std::marker::PhantomData,
}
}
}
}