use crate::{drop, error::Error};
type CueCtxHandle = usize;
unsafe extern "C" {
fn cue_newctx() -> CueCtxHandle;
}
pub struct Ctx(CueCtxHandle);
impl Drop for Ctx {
fn drop(&mut self) {
unsafe { drop::cue_free(self.0) }
}
}
impl Ctx {
pub(crate) fn handle(&self) -> usize {
self.0
}
pub fn new() -> Result<Self, Error> {
let handle = unsafe { cue_newctx() };
if handle == 0 {
return Err(Error::ContextCreationFailed);
}
Ok(Self(handle))
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::Ctx;
#[test]
fn test_new_succeeds() {
assert!(Ctx::new().is_ok());
}
}