use crate::qjs;
use std::{cell::Cell, sync::Once};
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "classes")))]
pub struct ClassId {
id: Cell<qjs::JSClassID>,
once: Once,
}
unsafe impl Send for ClassId {}
unsafe impl Sync for ClassId {}
impl ClassId {
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
Self {
id: Cell::new(0),
once: Once::new(),
}
}
pub fn get(&self) -> qjs::JSClassID {
self.init();
self.id.get()
}
fn init(&self) {
self.once.call_once(|| {
let mut id = 0;
unsafe { qjs::JS_NewClassID(&mut id) };
self.id.set(id);
})
}
}