wiwi/lsl/
ident.rs

1use crate::prelude::*;
2use crate::rc::RcThread;
3
4/// Identifier incrementer for generating unique LSL identifiers
5pub struct IdentIncrementer {
6	next: RcThread<cell::Cell<u64>>
7}
8
9impl IdentIncrementer {
10	pub fn new() -> Self {
11		Self { next: RcThread::from_value(cell::Cell::new(0)) }
12	}
13
14	pub fn next(&self) -> Ident {
15		let ident = self.next.as_value_ref().get();
16		self.next.as_value_ref().set(ident.checked_add(1).unwrap());
17		Ident { ident }
18	}
19}
20
21impl Clone for IdentIncrementer {
22	fn clone(&self) -> Self {
23		Self { next: RcThread::clone(&self.next) }
24	}
25}
26
27#[derive(Clone)]
28pub struct Ident {
29	ident: u64
30}
31
32impl Ident {
33	fn to_u64(&self) -> u64 {
34		self.ident
35	}
36}