struct Err(T)

Overview

Result error .

Defined in:

result.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Result(T)

err? : Bool err?, initialize initialize, ok? : Bool ok?, state : Tuple(Symbol, Symbol, T) state, status : Symbol status, status?(s : Symbol) : Bool status?, type : Symbol type, unwrap unwrap, value : T value

Constructor methods inherited from struct Result(T)

new new

Class methods inherited from struct Result(T)

err? : Bool err?, ok? : Bool ok?

Constructor Detail

def self.[](exception) : Err #

Syntax sugar for Err.fail(exception). exception must be an Exception or a String.

Err["Oops"] # => same as Err.fail("Oops")

[View source]
def self.conflict(exception) : Err #

Creates a new Err instance with the status :conflict. This method is a shortcut for Err.new :conflict, exception.

res = Err.conflict(exception)
res.status # => :conflict

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]
def self.fail(exception) : Err #

Creates a new Err instance with the status :fail. This method is a shortcut for Err.new :fail, exception.

res = Err.fail(exception)
res.status # => :fail

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]
def self.input(exception) : Err #

Creates a new Err instance with the status :input. This method is a shortcut for Err.new :input, exception.

res = Err.input(exception)
res.status # => :input

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]
def self.new(status : Symbol, exception : T) #

Creates a new Err instance with a custom #status.


[View source]
def self.new(exception : T) #

[View source]
def self.not_allowed(exception) : Err #

Creates a new Err instance with the status :not_allowed. This method is a shortcut for Err.new :not_allowed, exception.

res = Err.not_allowed(exception)
res.status # => :not_allowed

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]
def self.not_found(exception) : Err #

Creates a new Err instance with the status :not_found. This method is a shortcut for Err.new :not_found, exception.

res = Err.not_found(exception)
res.status # => :not_found

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]
def self.timeout(exception) : Err #

Creates a new Err instance with the status :timeout. This method is a shortcut for Err.new :timeout, exception.

res = Err.timeout(exception)
res.status # => :timeout

# Raise
res.unwrap

# Or get the exception value
pp res.value

[View source]

Class Method Detail

def self.type : Symbol #

Result type as a Symbol.

Err.type # => :err

[View source]

Instance Method Detail

def status : Symbol #
Description copied from struct Result(T)

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


def type : Symbol #

Result type as a Symbol.

res.type # => :err

[View source]
def unwrap #

Unwrap the result #value (like Result::unwrap in Rust). This method raises exception.


[View source]
def value : T #

Returns the result value. Returns a Exception or a String


[View source]