Skip to main content

runmat_core/
lib.rs

1#![allow(clippy::result_large_err)]
2
3#[cfg(all(test, target_arch = "wasm32"))]
4wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
5
6pub mod abi;
7mod error;
8mod execution;
9mod fusion;
10mod profiling;
11mod session;
12mod source_pool;
13mod telemetry;
14mod value_metadata;
15mod workspace;
16
17pub use error::{runtime_error_telemetry_failure_info, RunError};
18pub use execution::*;
19pub use fusion::*;
20pub use runmat_parser::CompatMode;
21pub use session::RunMatSession;
22pub use telemetry::{
23    TelemetryFailureInfo, TelemetryHost, TelemetryPlatformInfo, TelemetryRunConfig,
24    TelemetryRunFinish, TelemetryRunGuard, TelemetrySink,
25};
26pub use value_metadata::{
27    approximate_size_bytes, matlab_class_name, numeric_dtype_label, preview_numeric_values,
28    value_shape,
29};
30pub use workspace::*;
31
32#[cfg(test)]
33mod tests;
34
35/// Test-only helper that executes a text source via `ExecutionRequest`.
36#[cfg(not(target_arch = "wasm32"))]
37pub fn execute_text_request_for_testing(
38    session: &mut RunMatSession,
39    source_text: &str,
40) -> Result<SessionExecutionResult, RunError> {
41    let request = abi::ExecutionRequest::for_source(
42        abi::SourceInput::Text {
43            name: "<test>".to_string(),
44            text: source_text.to_string(),
45        },
46        session.compat_mode(),
47        abi::HostExecutionPolicy::default(),
48        session.workspace_handle(),
49    );
50    let outcome = futures::executor::block_on(session.execute_request(request))?;
51    let workspace = session.workspace_snapshot();
52    let warnings = outcome
53        .diagnostics
54        .iter()
55        .filter(|diag| diag.severity == abi::DiagnosticSeverity::Warning)
56        .map(|diag| runmat_runtime::warning_store::RuntimeWarning {
57            identifier: diag.code.clone(),
58            message: diag.message.clone(),
59        })
60        .collect();
61    Ok(SessionExecutionResult {
62        value: outcome.flow.durable_workspace_value().cloned(),
63        execution_time_ms: outcome.execution_time_ms,
64        used_jit: outcome.used_jit,
65        error: None,
66        type_info: outcome.type_info,
67        streams: outcome.streams,
68        workspace,
69        figures_touched: outcome.figures_touched,
70        warnings,
71        profiling: outcome.profiling,
72        fusion_plan: outcome.fusion_plan,
73        stdin_events: outcome.stdin_events,
74    })
75}