Skip to main content

zerodds_corba_rust/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Fehler-Familie des CORBA-Rust-Codegens.
4
5use core::fmt;
6
7/// Fehler beim Erzeugen von CORBA-Rust-Service-Code.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum CorbaRustError {
10    /// IDL-Konstrukt wird vom Rust-Service-Codegen aktuell nicht
11    /// unterstuetzt.
12    Unsupported {
13        /// Konstrukt-Name (z.B. `"abstract interface"`).
14        what: &'static str,
15        /// Position im IDL-Source (Byte-Offset).
16        at: usize,
17    },
18    /// Type-Reference konnte nicht aufgeloest werden.
19    UnresolvedType {
20        /// Voll-qualifizierter Name.
21        scoped: String,
22    },
23    /// Fehler im DataType-Codegen (idl-rust) durchgereicht.
24    DataType(zerodds_idl_rust::RustGenError),
25}
26
27impl fmt::Display for CorbaRustError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            Self::Unsupported { what, at } => {
31                write!(
32                    f,
33                    "corba-rust-codegen: unsupported IDL construct `{what}` at offset {at}"
34                )
35            }
36            Self::UnresolvedType { scoped } => {
37                write!(f, "corba-rust-codegen: unresolved type `{scoped}`")
38            }
39            Self::DataType(e) => write!(f, "corba-rust-codegen: data-type emit failed: {e}"),
40        }
41    }
42}
43
44impl std::error::Error for CorbaRustError {}
45
46impl From<zerodds_idl_rust::RustGenError> for CorbaRustError {
47    fn from(e: zerodds_idl_rust::RustGenError) -> Self {
48        Self::DataType(e)
49    }
50}
51
52/// Result-Alias.
53pub type Result<T> = core::result::Result<T, CorbaRustError>;