// Crate-level lint overrides (workspace lints enabled in Cargo.toml) #![allow(unsafe_code)] //! RustyTorch++ Language Bindings and SDK //! //! This crate provides language bindings for RustyTorch++, enabling usage from: //! - Python (via PyO3) //! - C/C++ (via C API) //! - Java/Node.js (via C API + JNI/N-API) //! - WebAssembly (via wasm-bindgen) //! //! The design emphasizes: //! - Zero-copy operations where possible //! - Type safety across language boundaries //! - Async operation support //! - Comprehensive error handling //! - Production-ready performance #![allow(unexpected_cfgs)] use thiserror::Error; #[cfg(feature = "python")] pub mod python; #[cfg(feature = "c-api")] pub mod c_api; #[cfg(feature = "onnx")] pub mod onnx; #[cfg(feature = "dlpack")] pub mod dlpack; /// Error types for language bindings #[derive(Error, Debug)] pub enum BindingError { #[error("Tensor shape mismatch: expected {expected:?}, got {actual:?}")] ShapeError { expected: Vec, actual: Vec, }, #[error("Device error: {message}")] DeviceError { message: String }, #[error("Out of memory: {message}")] OutOfMemoryError { message: String }, #[error("Type conversion error: {message}")] ConversionError { message: String }, #[error("Runtime error: {message}")] RuntimeError { message: String }, #[error("Tensor error: {0}")] TensorError(#[from] rtx_tensor::TensorError), #[error("Autograd error: {message}")] AutogradError { message: String }, // #[error("Inference error: {0}")] // InferenceError(#[from] rtx_inference::error::InferenceError), #[error("IO error: {0}")] IoError(#[from] std::io::Error), #[error("Serialization error: {0}")] #[cfg(feature = "onnx")] SerializationError(#[from] serde_json::Error), } pub type Result = std::result::Result; // Re-export core types for convenience pub use rtx_autograd::AutogradContext; pub use rtx_tensor::{DType, Device, Shape, Tensor}; // Python bindings temporarily disabled due to version conflicts // #[cfg(feature = "python")] // use pyo3::prelude::*; // #[cfg(feature = "python")] // use pyo3::exceptions::PyRuntimeError; #[cfg(test)] mod tests { use super::*; #[test] fn test_error_conversion() { // Test that our error types convert properly let tensor_err = rtx_tensor::TensorError::Shape { message: "Shape mismatch: expected [2, 3], got [3, 2]".to_string(), }; let binding_err = BindingError::from(tensor_err); match binding_err { BindingError::TensorError(_) => (), _ => panic!("Expected TensorError conversion"), } } }