Crate kotlin_poet_rs
source ·Expand description
§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"
§Features
§Experimental
Some library functions are under experimental
feature flag.
These features are unstable and could be changed in the near future, use it at your own risk.
§Philosophy
§Explicit better then implicit
RustPoet will not generate code that you did not ask 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
.
Modules§
- Describes common tokens used by Kotlin language.