use crate::error::Error;
use crate::license::LicenseType;
#[derive(Debug)]
pub struct HeldLicense<'engine> {
engine: &'engine crate::Engine,
handle: i32,
kind: LicenseType,
}
impl<'engine> HeldLicense<'engine> {
pub(crate) const fn new(
engine: &'engine crate::Engine,
handle: i32,
kind: LicenseType,
) -> Self {
Self {
engine,
handle,
kind,
}
}
#[must_use]
pub const fn kind(&self) -> LicenseType {
self.kind
}
#[must_use]
pub const fn handle(&self) -> i32 {
self.handle
}
pub fn release(self) -> Result<(), Error> {
let held = core::mem::ManuallyDrop::new(self);
held.engine.release_license(held.handle)
}
}
impl Drop for HeldLicense<'_> {
fn drop(&mut self) {
let _ = self.engine.release_license(self.handle);
}
}