kellpossible / RustyTypes

Java types inspired by the Rust programming language

Repository from Github https://github.comkellpossible/RustyTypesRepository from Github https://github.comkellpossible/RustyTypes

RustyTypes for Java

This project is a collection of Java types which are inspired by the Rust programming language.

Types

This type is inspired by Rust's Result enum.

A Result method can be created by using its static constructor methods ofValue() or ofError() to create a result which contains either a result value or an error.

Result<ValueType, ErrorType> resultWithValue = Result.ofValue(value);
Result<ValueType, ErrorType> resultWithError = Result.ofError(error);

The only way to access the value inside the Result is to use the handle() method. This method has two overloaded implementations. One makes use of lambdas, and the other uses the ResultHandler interface along with its two methods. This method forces consumers of the Result to consider the implications of either a value being present or an error being present.

result.handle(
        value -> {
            // handle what happens if the result contains a value
        },
        error -> {
            // handle what happens if the result contains an error
        }
);

About

Java types inspired by the Rust programming language

License:MIT License


Languages

Language:Java 100.0%