Skip to main content

hub_codegen/generator/
mod.rs

1//! Code generation from IR
2
3#[cfg(feature = "typescript")]
4pub mod typescript;
5
6#[cfg(feature = "rust")]
7pub mod rust;
8
9use std::collections::HashMap;
10
11/// A warning emitted during code generation
12#[derive(Debug, Clone)]
13pub struct Warning {
14    pub location: String,
15    pub message: String,
16}
17
18impl std::fmt::Display for Warning {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        write!(f, "{}: {}", self.location, self.message)
21    }
22}
23
24/// Result of code generation
25pub struct GenerationResult {
26    /// Map of relative path -> file content
27    pub files: HashMap<String, String>,
28    /// Warnings encountered during generation
29    pub warnings: Vec<Warning>,
30    /// Map of relative path -> content hash (for cache invalidation)
31    pub file_hashes: HashMap<String, String>,
32    /// Runtime npm dependencies (name -> version range)
33    pub dependencies: HashMap<String, String>,
34    /// npm dev dependencies (name -> version range)
35    pub dev_dependencies: HashMap<String, String>,
36}
37
38/// Transport environment for generated code
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum TransportEnv { Ws, Browser, None }
41
42/// Options for code generation
43#[derive(Debug, Clone)]
44pub struct GenerationOptions {
45    pub transport: TransportEnv,
46}
47
48impl Default for GenerationOptions {
49    fn default() -> Self {
50        Self { transport: TransportEnv::Ws }
51    }
52}
53