tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definiciones

⎇ addde42e6481f13c15350f9fa5f98762774a50fa src/id.rs Rust · 27 líneas · 608 B Historia Quién tocó qué crudo

Cleanup imports (#75) addde42e6 · Andreas Weibye ·

1//! Identifier for a Node
2//!
3//!
4use core::sync::atomic::{AtomicUsize, Ordering};
5
6/// Internal node id.
7pub(crate) type NodeId = usize;
8
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10#[cfg_attr(not(any(feature = "std", feature = "alloc")), derive(hash32_derive::Hash32))]
11pub(crate) struct Id(usize);
12
13pub(crate) struct Allocator {
14    new_id: AtomicUsize,
15}
16
17impl Allocator {
18    pub const fn new() -> Self {
19        Self { new_id: AtomicUsize::new(0) }
20    }
21
22    pub fn allocate(&self) -> Id {
23        Id(self.new_id.fetch_add(1, Ordering::Relaxed))
24    }
25
26    pub fn free(&self, _ids: &[Id]) {}
27}