PointClickEngine::Core::Result(T, E)
Inherits Struct < Value < Object
Result type for operations that can succeed or fail
This provides a type-safe way to handle operations that might fail without relying on exceptions or nil returns. Inspired by Rust's Result type and functional programming error handling patterns.
Usage
def load_texture(path : String) : Result(Texture, AssetError)
if File.exists?(path)
texture = RL.load_texture(path)
Result(T, E).success(texture)
else
Result(T, E).failure(AssetError.new("File not found", path))
end
end
result = load_texture("sprite.png")
case result
when .success?
texture = result.value
# Use texture
when .failure?
puts "Error: #{result.error.message}"
end
Constructors
new(value : T | Nil, error : E | Nil, success : Bool)
Source