kust 0.0.2

Kotlin-like APIs for Rust
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented3 out of 3 items with examples
  • Size
  • Source code size: 7.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.14 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rChaoz/kust
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rChaoz

Kust

Write Rust like you never left Kotlin.

Kust aims to make new Rustaceans, familiar with Kotlin, feel right at home. It's also aimed to bring a few of Kotlin's goodies to the existing Rust community, without compromising on any of Rust's benefits.

Scope functions

Perform side effects and modify objects in a more concise and readable way.

Available functions:

  • using - use a value in an expression without creating a new variable (returns a new value)
  • also - perform a side effect using a value without modifying it (returns the same value)
  • apply - modify a value before returning it (returns the same value)

[!NOTE] The Kotlin let function has been renamed to using, as the let keyword is reserved in Rust.

See Kotlin documentation.

Examples

Using

use some::Person;
use kust::ScopeFunctions;

fn greet_person(encoded_person: &str) -> String {
    let name = Person::from_str(encoded_person).using(|person| format!("{} {}", person.first_name, person.last_name));
    println!("Hi, {name}!")
}

Also

use some::ComplexType;
use kust::ScopeFunctions;

fn parse_items(&items: Vec<&str>) -> Vec<ComplexType> {
    items
        // easily add a debug print for each item
        .map(|item| ComplexType::from_str(item).also(|it| println!("{it}")))
        .filter(|item| !item.is_empty())
        .collect()
}

Apply

use some::Person;
use kust::ScopeFunctions;

fn get_users() -> Vec<Person> {
    vec![
        // set an additional attribute
        Person::create("Mike").apply(|it| it.age = 34),
        Person::create("Linda").apply(|it| it.age = 25),
    ]
}