Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Could Rust adding extra indent with format! macro?
I'm writting a program that generate C# code using Rust, For example I have:
namespace Generated
{
public partial class Generated1
{
// things
}
public partial class Generated2
{
// things
}
}
Since Generated1 and Generated2 are complex, there is a single function that generate classes like Generated*, which yields the class without indent:
// println!("{}", generating(1)) yields:
public partial class Generated1
{
// things
}
I wonder is there some technique that allow formatting the generated items with extra indent. Since writting indent in the generating
function seems a lot of chaos:
// with indent
format!(
r#"{space:width$}public partial class Generated1
{space:width$}{{
{space:width_plus_1$}// things
{space:width$}}}"#, space = "", width = indent_level * 4, width_plus_1 = indent_level * 4);
// without indent
format!(
r#"public partial class Generated1
{{
// things
}}"#, space = "", width = indent_level * 4, width_plus_1 = indent_level * 4);
Is there some technique to format items with extra indent available in Rust?
2 posts - 2 participants
🏷️ Rust_feed