Crates.io | kotlin-poet-rs |
lib.rs | kotlin-poet-rs |
version | 0.9.0 |
source | src |
created_at | 2024-07-18 03:55:39.000945 |
updated_at | 2024-08-20 08:44:04.473788 |
description | Kotlin code generation library for Rust |
homepage | https://github.com/lexa-diky/kotlin-poet-rs |
repository | https://github.com/lexa-diky/kotlin-poet-rs |
max_upload_size | |
id | 1306887 |
size | 167,718 |
cargo add kotlin-poet-rs
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"
To see what features are currently supported and planned for the future, check roadmap.
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.
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.
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.
Rust IO is very versatile and comes in many shapes. Thus this project does not suggest any IO implementation.
This library is commited to be as little as possible.
It does not depend on any other library, except for std
.