memkit_async/
task_local.rs

1//! Task-local allocation context.
2
3use std::sync::Arc;
4
5/// Task-local allocation context.
6///
7/// Provides isolated allocation for each async task,
8/// with optional parent-child inheritance.
9pub struct MkTaskLocal {
10    inner: Arc<TaskLocalInner>,
11}
12
13struct TaskLocalInner {
14    parent: Option<Arc<TaskLocalInner>>,
15    // TODO: Add task-local state
16}
17
18impl MkTaskLocal {
19    /// Create a new root task-local context.
20    pub fn new() -> Self {
21        Self {
22            inner: Arc::new(TaskLocalInner { parent: None }),
23        }
24    }
25
26    /// Create a child context that inherits from this one.
27    pub fn child(&self) -> Self {
28        Self {
29            inner: Arc::new(TaskLocalInner {
30                parent: Some(Arc::clone(&self.inner)),
31            }),
32        }
33    }
34
35    /// Check if this context has a parent.
36    pub fn has_parent(&self) -> bool {
37        self.inner.parent.is_some()
38    }
39}
40
41impl Default for MkTaskLocal {
42    fn default() -> Self {
43        Self::new()
44    }
45}
46
47impl Clone for MkTaskLocal {
48    fn clone(&self) -> Self {
49        Self {
50            inner: Arc::clone(&self.inner),
51        }
52    }
53}