dagger-rs/crates/dagger-codegen/src/rust/format.rs
kjuulh 94336d0637 feat(sdk): move to &str instead of String and introduce builder.
This will make the api much easier to use, as we can now rely on ""
instead of "".into() for normal string values.

Introduced builder as well, which makes it much easier to use *Opts, as
it can handle the building of that, and get the benefits from String ->
&str, as that is currently not allowed for optional values
2023-02-19 18:00:04 +01:00

69 lines
1.9 KiB
Rust

use crate::functions::FormatTypeFuncs;
use super::functions::format_name;
pub struct FormatTypeFunc;
impl FormatTypeFuncs for FormatTypeFunc {
fn format_kind_list(&self, representation: &str, _input: bool, _immutable: bool) -> String {
format!("Vec<{}>", representation)
}
fn format_kind_scalar_string(&self, representation: &str, input: bool) -> String {
let mut rep = representation.to_string();
if input {
rep.push_str("impl Into<String>");
} else {
rep.push_str("String");
}
rep
}
fn format_kind_scalar_int(&self, representation: &str) -> String {
let mut rep = representation.to_string();
rep.push_str("isize");
rep
}
fn format_kind_scalar_float(&self, representation: &str) -> String {
let mut rep = representation.to_string();
rep.push_str("float");
rep
}
fn format_kind_scalar_boolean(&self, representation: &str) -> String {
let mut rep = representation.to_string();
rep.push_str("bool");
rep
}
fn format_kind_scalar_default(
&self,
representation: &str,
ref_name: &str,
_input: bool,
) -> String {
let mut rep = representation.to_string();
rep.push_str(&format_name(ref_name));
rep
}
fn format_kind_object(&self, representation: &str, ref_name: &str) -> String {
let mut rep = representation.to_string();
rep.push_str(&format_name(ref_name));
rep
}
fn format_kind_input_object(&self, representation: &str, ref_name: &str) -> String {
let mut rep = representation.to_string();
rep.push_str(&format_name(ref_name));
rep
}
fn format_kind_enum(&self, representation: &str, ref_name: &str) -> String {
let mut rep = representation.to_string();
rep.push_str(&format_name(ref_name));
rep
}
}