mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-03 07:14:01 -07:00
44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
//! Code generators for client libraries.
|
|
//!
|
|
//! Each language has its own submodule with focused files:
|
|
//! - `types.rs` - Type definitions
|
|
//! - `client.rs` - Base client and pattern factories
|
|
//! - `tree.rs` - Tree structure generation
|
|
//! - `api.rs` - API method generation
|
|
//! - `mod.rs` - Entry point
|
|
|
|
use std::fmt::Write;
|
|
|
|
pub mod javascript;
|
|
pub mod python;
|
|
pub mod rust;
|
|
|
|
pub use javascript::generate_javascript_client;
|
|
pub use python::generate_python_client;
|
|
pub use rust::generate_rust_client;
|
|
|
|
/// Types that are manually defined as generics in client code, not from schema.
|
|
pub const MANUAL_GENERIC_TYPES: &[&str] = &["MetricData", "MetricEndpoint"];
|
|
|
|
/// Write a multi-line description with the given prefix for each line.
|
|
/// `empty_prefix` is used for blank lines (e.g., " *" without trailing space).
|
|
pub fn write_description(output: &mut String, desc: &str, prefix: &str, empty_prefix: &str) {
|
|
for line in desc.lines() {
|
|
if line.is_empty() {
|
|
writeln!(output, "{}", empty_prefix).unwrap();
|
|
} else {
|
|
writeln!(output, "{}{}", prefix, line).unwrap();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Replace generic types with their Any variants in return types.
|
|
/// Used by JS and Python generators.
|
|
pub fn normalize_return_type(return_type: &str) -> String {
|
|
let mut result = return_type.to_string();
|
|
for type_name in MANUAL_GENERIC_TYPES {
|
|
result = result.replace(type_name, &format!("Any{}", type_name));
|
|
}
|
|
result
|
|
}
|