abstract struct Result(T)

Overview

Wrap a value into a Result (like in Rust).

Direct Known Subclasses

Defined in:

result.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.err? : Bool #

Returns true if current Result class is Err, false otherwise.


[View source]
def self.ok? : Bool #

Returns true if current Result class is Ok, false otherwise.


[View source]

Instance Method Detail

def err? : Bool #

Returns true if current Result instance is Err, false otherwise.


[View source]
def initialize #

[View source]
def ok? : Bool #

Returns true if current Result instance is Ok, false otherwise.


[View source]
def state : Tuple(Symbol, Symbol, T) #

Extract the Result state (#type, #status and #value). Inspired by the Elixir lang approach, it's handy for the pattern matching.


[View source]
abstract def status : Symbol #

Result status as a Symbol (:done or :fail, etc).


[View source]
def status?(s : Symbol) : Bool #

Checks a #status.

res.status?(:done)
res.status?(:fail)

[View source]
abstract def type : Symbol #

Result type as a Symbol (:ok or :err).


[View source]
abstract def unwrap #

Unwrap the result #value (like Result::unwrap in Rust).


[View source]
abstract def value : T #

Returns the result value.


[View source]