tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ e69717ab10539e5abe2f2778a050ba795853f96b 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}