Skip to main content

zerodds_corba_rust/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Error family of the CORBA Rust codegen.
4
5use core::fmt;
6
7/// Error while generating CORBA Rust service code.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum CorbaRustError {
10    /// IDL construct currently not supported by the Rust service codegen.
11    Unsupported {
12        /// Construct name (e.g. `"abstract interface"`).
13        what: &'static str,
14        /// Position in the IDL source (byte offset).
15        at: usize,
16    },
17    /// Type reference could not be resolved.
18    UnresolvedType {
19        /// Fully qualified name.
20        scoped: String,
21    },
22    /// Error from the DataType codegen (idl-rust) passed through.
23    DataType(zerodds_idl_rust::RustGenError),
24}
25
26impl fmt::Display for CorbaRustError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::Unsupported { what, at } => {
30                write!(
31                    f,
32                    "corba-rust-codegen: unsupported IDL construct `{what}` at offset {at}"
33                )
34            }
35            Self::UnresolvedType { scoped } => {
36                write!(f, "corba-rust-codegen: unresolved type `{scoped}`")
37            }
38            Self::DataType(e) => write!(f, "corba-rust-codegen: data-type emit failed: {e}"),
39        }
40    }
41}
42
43impl std::error::Error for CorbaRustError {}
44
45impl From<zerodds_idl_rust::RustGenError> for CorbaRustError {
46    fn from(e: zerodds_idl_rust::RustGenError) -> Self {
47        Self::DataType(e)
48    }
49}
50
51/// Result alias.
52pub type Result<T> = core::result::Result<T, CorbaRustError>;