1use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9pub mod connection;
10pub mod execution;
11#[cfg(feature = "jupyter")]
12pub mod jupyter_plotting;
13pub mod protocol;
14pub mod server;
15pub mod transport;
16
17pub use connection::ConnectionInfo;
18pub use execution::ExecutionEngine;
19pub use jupyter_plotting::{
20 DisplayData, JupyterPlottingConfig, JupyterPlottingExtension, JupyterPlottingManager,
21};
22pub use protocol::{ExecuteReply, ExecuteRequest, JupyterMessage, MessageType};
23pub use server::KernelServer;
24
25#[derive(Debug, Clone)]
27pub struct KernelConfig {
28 pub connection: ConnectionInfo,
30 pub session_id: String,
32 pub debug: bool,
34 pub execution_timeout: Option<u64>,
36}
37
38impl Default for KernelConfig {
39 fn default() -> Self {
40 Self {
41 connection: ConnectionInfo::default(),
42 session_id: Uuid::new_v4().to_string(),
43 debug: false,
44 execution_timeout: Some(300), }
46 }
47}
48
49#[derive(Debug, Serialize, Deserialize)]
51pub struct KernelInfo {
52 pub protocol_version: String,
53 pub implementation: String,
54 pub implementation_version: String,
55 pub language_info: LanguageInfo,
56 pub banner: String,
57 pub help_links: Vec<HelpLink>,
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61pub struct LanguageInfo {
62 pub name: String,
63 pub version: String,
64 pub mimetype: String,
65 pub file_extension: String,
66 pub pygments_lexer: String,
67 pub codemirror_mode: String,
68}
69
70#[derive(Debug, Serialize, Deserialize)]
71pub struct HelpLink {
72 pub text: String,
73 pub url: String,
74}
75
76impl Default for KernelInfo {
77 fn default() -> Self {
78 Self {
79 protocol_version: "5.3".to_string(),
80 implementation: "runmat".to_string(),
81 implementation_version: "0.0.1".to_string(),
82 language_info: LanguageInfo {
83 name: "matlab".to_string(),
84 version: "R2025a-compatible".to_string(),
85 mimetype: "text/x-matlab".to_string(),
86 file_extension: ".m".to_string(),
87 pygments_lexer: "matlab".to_string(),
88 codemirror_mode: "octave".to_string(),
89 },
90 banner: "RunMat - Fast, Free, Modern MATLAB code runtime".to_string(),
91 help_links: vec![HelpLink {
92 text: "RunMat Documentation".to_string(),
93 url: "https://github.com/runmat-org/runmat".to_string(),
94 }],
95 }
96 }
97}
98
99#[derive(Debug, thiserror::Error)]
101pub enum KernelError {
102 #[error("ZMQ error: {0}")]
103 Zmq(#[from] zmq::Error),
104 #[error("JSON serialization error: {0}")]
105 Json(#[from] serde_json::Error),
106 #[error("Execution error: {0}")]
107 Execution(String),
108 #[error("Protocol error: {0}")]
109 Protocol(String),
110 #[error("Connection error: {0}")]
111 Connection(String),
112 #[error("Internal error: {0}")]
113 Internal(String),
114}
115
116pub type Result<T> = std::result::Result<T, KernelError>;