Skip to main content

kernel_api/
kernel.rs

1//! The kernel itself: its trait, its error and its result, with the rebuild
2//! stubs kept until 0.2.
3
4use serde::{Deserialize, Serialize};
5use std::path::Path;
6use thiserror::Error;
7
8use crate::*;
9
10/// Convenience alias for kernel fallible operations.
11pub type KernelResult<T> = Result<T, KernelError>;
12
13/// Handle to a body managed by the kernel.
14#[deprecated(since = "0.1.6", note = "never called; removed in 0.2")]
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
16pub struct BodyHandle(pub u64);
17
18/// Request describing which features or bodies must be recomputed.
19#[deprecated(since = "0.1.6", note = "never called; removed in 0.2")]
20#[derive(Debug, Clone, Default, Serialize, Deserialize)]
21pub struct RebuildRequest {
22    /// Feature identifiers that triggered the rebuild.
23    pub dirty_features: Vec<String>,
24    /// Whether dependent features should be recomputed automatically.
25    pub propagate: bool,
26}
27
28/// Response returned for every rebuild invocation.
29#[deprecated(since = "0.1.6", note = "never called; removed in 0.2")]
30#[derive(Debug, Clone, Default, Serialize, Deserialize)]
31pub struct RebuildResponse {
32    /// Bodies that were modified or regenerated.
33    #[allow(deprecated)]
34    pub updated_bodies: Vec<BodyHandle>,
35    /// Kernel provided diagnostics or warnings.
36    pub diagnostics: Vec<String>,
37}
38
39/// Trait implemented by any geometry kernel that can serve the application.
40#[allow(deprecated)]
41pub trait Kernel: Send {
42    /// Human-friendly identifier for logging purposes.
43    fn name(&self) -> &str;
44
45    /// Called once before any geometry work happens.
46    fn initialize(&mut self) -> KernelResult<()>;
47
48    /// Recompute dirty features/bodies and return the affected handles.
49    #[deprecated(since = "0.1.6", note = "never called; removed in 0.2")]
50    fn rebuild(&mut self, _request: &RebuildRequest) -> KernelResult<RebuildResponse> {
51        Err(KernelError::Unsupported("rebuild".into()))
52    }
53
54    /// Produce a triangular mesh for the provided body handle.
55    #[deprecated(since = "0.1.6", note = "never called; removed in 0.2")]
56    fn tessellate(
57        &self,
58        _body: BodyHandle,
59        _detail: &TessellationSettings,
60    ) -> KernelResult<TriMesh> {
61        Err(KernelError::Unsupported("tessellate".into()))
62    }
63
64    /// Read a STEP/STP file from disk and return tessellated bodies.
65    ///
66    /// Implementations that do not support STEP import should return
67    /// [`KernelError::Unsupported`].
68    fn import_step(
69        &mut self,
70        _path: &Path,
71        _detail: &TessellationSettings,
72    ) -> KernelResult<ImportedModel> {
73        Err(KernelError::Unsupported(
74            "STEP import is not implemented by this kernel".into(),
75        ))
76    }
77}
78
79/// Standardized error type for kernel interactions.
80#[derive(Debug, Error)]
81pub enum KernelError {
82    #[error("kernel initialization failed: {0}")]
83    Initialization(String),
84    #[error("kernel not initialized")]
85    NotInitialized,
86    #[error("operation unsupported: {0}")]
87    Unsupported(String),
88    #[error("invalid kernel input: {0}")]
89    InvalidInput(String),
90    #[error("import failed: {0}")]
91    Import(String),
92    #[error(transparent)]
93    Other(#[from] anyhow::Error),
94}