Other languages: 中文, En français.
Quick Start
After reading through this article, you will master the usage of:
Resultat<T>as return typeassert_throw!(...)throw!(...).catch()?and.catch_()?.ifnone()?and.ifnone_()?
1. Example of returning Resultat<T>
use *;
NOTE: If you are writing your own fail-able function, let it return Resultat<T>.
2. Example of assert_throw!(...)
use *;
NOTE: if exactly one optional arg is given, the arg is treated as error message, and the title is automatically set to "AssertionFailedException".
3. Example of throw!(...)
4. Example of .catch(...)? and .catch_()?
4.1. Full catch
This is extremely useful when the underlying error message is confusing. The programmer is responsible for customizing helpful error message.
use *;
use File;
4.2. Lazy catch
If the underlying error message is helpful enough, use lazy catch to track the call stack and propagate the error message.
use *;
use ;
5. Example of .ifnone(...)? and .ifnone_()?
If an Option::None stucks your business, call .ifnone(...)? or .ifnone_()? to throw an error.
use HashMap;
use *;
use Rng;