zerodds_idl_rust/error.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Fehler-Familie des Rust-Codegens.
4
5use core::fmt;
6
7/// Fehler beim Erzeugen von Rust-Code aus dem IDL-AST.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum RustGenError {
10 /// IDL-Konstrukt wird vom Rust-Codegen aktuell nicht unterstuetzt.
11 ///
12 /// Ist kein Spec-Bug — manche IDL-Features (Fixed, Map, Any, Bitset,
13 /// Bitmask, Valuetype, Interface, Component, Home) sind ausserhalb
14 /// des DDS-DataType-Pfades. Wer DDS-DataTypes generiert braucht sie
15 /// nicht.
16 Unsupported {
17 /// Konstrukt-Name (z.B. `"fixed"`).
18 what: &'static str,
19 /// Position im IDL-Source (Byte-Offset vom AST-Span).
20 at: usize,
21 },
22 /// Annotation-Wert konnte nicht ausgewertet werden.
23 InvalidAnnotation {
24 /// Annotation-Name (z.B. `"@id"`).
25 name: String,
26 /// Begruendung.
27 reason: &'static str,
28 },
29 /// Type-Reference konnte nicht aufgeloest werden.
30 UnresolvedType {
31 /// Voll-qualifizierter Name.
32 scoped: String,
33 },
34}
35
36impl fmt::Display for RustGenError {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self {
39 Self::Unsupported { what, at } => {
40 write!(
41 f,
42 "rust-codegen: unsupported IDL construct `{what}` at offset {at}"
43 )
44 }
45 Self::InvalidAnnotation { name, reason } => {
46 write!(f, "rust-codegen: invalid annotation `{name}`: {reason}")
47 }
48 Self::UnresolvedType { scoped } => {
49 write!(f, "rust-codegen: unresolved type `{scoped}`")
50 }
51 }
52 }
53}
54
55impl std::error::Error for RustGenError {}
56
57/// Result-Alias.
58pub type Result<T> = core::result::Result<T, RustGenError>;