19 releases (9 breaking)
0.9.0 | Aug 20, 2024 |
---|---|
0.7.1-indev | Aug 8, 2024 |
0.6.0-indev | Jul 26, 2024 |
#120 in Template engine
145KB
3.5K
SLoC
KotlinPoet-RS
Get Started
Add dependency
cargo add kotlin-poet-rs
Read documentation
Start writing poetry
Constant property with initializer:
use kotlin_poet_rs::spec::{CodeBlock, Name, Property, Type};
use kotlin_poet_rs::io::RenderKotlin;
let property = Property::new(Name::from("name"), Type::string())
.constant(true)
.initializer(CodeBlock::atom("\"Alex\""));
println!("{}", property.render_string());
Will print:
public final const val name: kotlin.String = "Alex"
Supported features
To see what features are currently supported and planned for the future, check roadmap.
Philosophy
Explicit better then implicit
RustPoet will not generate code that you did not asked it to generate. No magic import resolution, no magic type inference, no magic anything.
For example, as you can see in example in Get Started
section generated code will have
explicit fully qualified type name for name
property.
Same principle applies redundant for public
and final
keywords.
Writer not reader
RustPoet is designed to be used by humans to generate code that humans can read. Not for describing Kotlin code in some abstract way. This library is write only, don't use it to represent and manipulate Kotlin code.
KotlinPoet / JavaPoet has issues
This project acknowledges that original KotlinPoet and JavaPoet has some issues. It aims to fix them and provide better API for generating Kotlin code. We don't strife to provide exact same API.
No built-in IO
Rust IO is very versatile and comes in many shapes. Thus this project does not suggest any IO implementation.
No dependencies
This library is commited to be as little as possible.
It does not depend on any other library, except for std
.