Class: Errgonomic::Result::Err

Inherits:
Any show all
Defined in:
lib/errgonomic/result.rb

Overview

The Err variant. It always carries an error, so unwrap_err! and a pattern variable bind what the caller put there.

Examples:

an Err without an error raises

Err(:e).unwrap_err! # => :e
Err() # => raise ArgumentError, "wrong number of arguments (given 0, expected 1)"
Errgonomic::Result::Err.new # => raise ArgumentError, "wrong number of arguments (given 0, expected 1)"

Err(nil) is an ordinary Err that holds nil

Err(nil).inspect # => "Err(nil)"
Err(nil).unwrap_err! # => nil
Err(nil).deconstruct # => [nil]
case Err(nil)
in Ok(value) then [:ok, value]
in Err(e) then [:err, e]
end # => [:err, nil]

Constant Summary

Constants inherited from Any

Any::RUST_SPELLINGS

Instance Method Summary collapse

Methods inherited from Any

#!=, #<=>, #==, #===, #and, #and_then, #as_json, #deconstruct, #eql?, #err_and?, #expect!, #hash, #initialize, #map, #map_err, #method_missing, #ok_and?, #or, #or_else, #pretty_print, #respond_to_missing?, #result?, #tap_err, #tap_ok, #to_json, #to_s, #unwrap!, #unwrap_err!, #unwrap_or, #unwrap_or_else

Constructor Details

This class inherits a constructor from Errgonomic::Result::Any

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Errgonomic::Result::Any

Instance Method Details

#err?Boolean

Err is always err

Examples:

Err(:z).err? # => true

Returns:

  • (Boolean)


632
633
634
# File 'lib/errgonomic/result.rb', line 632

def err?
  true
end

#inspectObject

Render like Rust's Debug, delegating to the inner value's inspect.

Examples:

Err(:nope).inspect # => "Err(:nope)"
Err(Some(1)).inspect # => "Err(Some(1))"


649
650
651
# File 'lib/errgonomic/result.rb', line 649

def inspect
  "Err(#{value.inspect})"
end

#ok?Boolean

Err is never ok

Examples:

Err(:A).ok? # => false

Returns:

  • (Boolean)


640
641
642
# File 'lib/errgonomic/result.rb', line 640

def ok?
  false
end