Self advertisement. Ever wanted to generate Kotli...
# random
a
Self advertisement. Ever wanted to generate Kotlin code using Rust? Probably not, but you can do it now with KotlinPoetRs library pepe clap. Public interfaces are heavily inspired by Java and KotlinPoet libraries, so it is pretty easy to use if you are already familiar with them. Supported features:🏛️ High level / In class: Classes, Functions, Properties, Type Aliases • kodee electrified Different types of class: sealed, interface, abstract, enum, objects • 📄 Annotations and KDoc Library has relatively unstable interface but close to feature completion. If you have any ideas / wishes please leave it in a thread.
😂 3
🎉 4
y
Very interesting idea! Haven't used Rust but to my understanding there's heavy focus on memory management and lifetimes and things. Does that get in the way of this library's ergonomics?
a
This library is quite simple, because it is basically bunch of builders -> no complex lifetime management inside. I could have done some things in more efficient manner but i don’t see any benefit in additional 10% performance, when it is already very fast. Overall my experience doing it was not very different from using Kotlin. Only thing different that I really liked is simplicity of benchmarking. JMH is flexible and very powerful, but is a huge pain to setup. While criterion-rs is just 2 lines of code and you are getting data you need.
Regarding ergonomics, i was a little bit frustrated without full featured inheritance, some things would be way simpler. Plus Kotlin’s
sealed class
is somewhat more flexible then Rust
enum
, so there is some questionable things in API, for example I have to have both enum with variant
Type::ClassLike
and structure
ClassLikeType
because you can’t have a function that accepts instance of specific enum variant.
On other hand macros are great (but i see why Kotlin is missing it). For example this bad boy allows for defining bunch of ‘generic’ factory functions in code without much of copy-paste:
Copy code
fn_generic_type_factory!(map, kotlin.collections, Map<key, value>);
    fn_generic_type_factory!(list, kotlin.collections, List<value>);
    fn_generic_type_factory!(set, kotlin.collections, Set<value>);
    fn_generic_type_factory!(array, kotlin, Array<value>);
s
„Probably not, but you can do it now“ together with that emoji just killed me 😂 😂 😂