Skip to content

Instantly share code, notes, and snippets.

Rust Error Handling Cheatsheet - Result handling functions

Introduction to Rust error handling

Rust error handling is nice but obligatory. Which makes it sometimes plenty of code.

Functions return values of type Result that is "enumeration". In Rust enumeration means complex value that has alternatives and that alternative is shown with a tag.

Result is defined as Ok or Err. The definition is generic, and both alternatives have

@mstum
mstum / Benchmark.txt
Last active December 4, 2024 16:53
Fully Managed alternative to StrCmpLogicalW
BenchmarkDotNet=v0.10.13, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.309)
Intel Core i7-6700HQ CPU 2.60GHz (Skylake), 1 CPU, 8 logical cores and 4 physical cores
Frequency=2531253 Hz, Resolution=395.0613 ns, Timer=TSC
[Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2633.0
Clr : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2633.0
Job=Clr Runtime=Clr
Method | Mean | Error | StdDev | Allocated |
---------------------------- |---------:|---------:|---------:|----------:|
@bchase
bchase / new_phoenix_dot_iex.exs
Last active October 26, 2016 19:08
Officially tired of aliasing `Repo` and importing `Ecto.Query` by hand every IEx session
#!/usr/bin/env elixir
ecto_import = "import Ecto.Query, only: [from: 2]"
mixexs =
Path.join(["mix.exs"])
|> File.read!
namespace =
Regex.run(~r{defmodule\s+(\w+)\.}, mixexs)