Skip to main content

openapi_nexus/generators/rust/reqwest/
runtime.rs

1//! Hardcoded Rust runtime source files.
2//!
3//! The runtime provides a reqwest-based `Client`, `Error` enum, and `Auth`
4//! trait. These ship as-is in every generated SDK.
5
6use crate::codegen::traits::file_writer::FileInfo;
7
8const CLIENT_RS: &str = include_str!("runtime/client.rs.txt");
9const ERROR_RS: &str = include_str!("runtime/error.rs.txt");
10const AUTH_RS: &str = include_str!("runtime/auth.rs.txt");
11const MOD_RS: &str = include_str!("runtime/mod.rs.txt");
12
13/// Returns runtime files ready to write.
14pub fn runtime_files(header: &str) -> Vec<FileInfo> {
15    vec![
16        FileInfo::runtime("client.rs".to_string(), with_header(header, CLIENT_RS)),
17        FileInfo::runtime("error.rs".to_string(), with_header(header, ERROR_RS)),
18        FileInfo::runtime("auth.rs".to_string(), with_header(header, AUTH_RS)),
19        FileInfo::runtime("mod.rs".to_string(), with_header(header, MOD_RS)),
20    ]
21}
22
23fn with_header(header: &str, body: &str) -> String {
24    let mut out = String::with_capacity(header.len() + body.len());
25    out.push_str(header);
26    out.push_str(body);
27    out
28}