Skip to content

kellpossible/RustyTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages