Skip to main content

laddu_kernel/
spec.rs

1use std::sync::Arc;
2
3use serde::{Deserialize, Serialize};
4
5/// Stable user-facing name of a computational kernel.
6#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct KernelName(Arc<str>);
8
9impl KernelName {
10    /// Creates a kernel name.
11    pub fn new(name: impl Into<Arc<str>>) -> Self {
12        Self(name.into())
13    }
14
15    /// Returns the name as a string slice.
16    pub fn as_str(&self) -> &str {
17        &self.0
18    }
19}
20
21/// Stable user-facing name of a cached event quantity.
22#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
23pub struct CacheName(Arc<str>);
24
25impl CacheName {
26    /// Creates a cache name.
27    pub fn new(name: impl Into<Arc<str>>) -> Self {
28        Self(name.into())
29    }
30
31    /// Returns the name as a string slice.
32    pub fn as_str(&self) -> &str {
33        &self.0
34    }
35}
36
37/// Declarative specification for a named kernel.
38#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
39pub struct KernelSpec {
40    name: KernelName,
41}
42
43impl KernelSpec {
44    /// Creates a named kernel specification.
45    pub fn new(name: impl Into<Arc<str>>) -> Self {
46        Self {
47            name: KernelName::new(name),
48        }
49    }
50
51    /// Returns the kernel name.
52    pub fn name(&self) -> &KernelName {
53        &self.name
54    }
55}
56
57/// Creates a named [`KernelSpec`].
58pub fn kernel(name: impl Into<Arc<str>>) -> KernelSpec {
59    KernelSpec::new(name)
60}