cause
[Cause] is a tiny generic implementation of the [std::error::Error] trait.
It takes 1 type parameter(T: Debug
) who describes what error type happened.
It is dereferencable as &T
.
And if you use macro [cause], it automatically stores some extra information,
the filename and line number, only when it was compiled with debug_assertions
.
Examples
use *;
use Cause;
use Error;
// It creates an instance of `Cause<ErrorType>`
let cause = new;
assert_eq!;
assert!;
assert!;
// It is dereferencable.
assert_eq!;
let http_status_code = match *cause ;
assert_eq!;
// set the message:
let cause = new.msg;
assert_eq!;
assert_eq!;
assert!;
// set the source of this error (any error type can be set with `src()`):
let cause = new.src;
assert_eq!;
assert!;
assert!;
// an example of Cause who have a standard io error.
use Error as IoErr;
use ErrorKind;
let io_err = new;
println!;
// a couple of macro examples
use cause;
let cause = cause!;
println!;
// => "InternalError" on release build
// => "InternalError: [lib.rs:64]" on debug build
let cause = cause!;
println!;
// => "InternalError: There is no such contents." on release build
// => "InternalError: There is no such contents. [lib.rs:69]" on debug build
Changelog
0.1.2
- Fixed
cause
macro issue thatuse cause::Cause
was implicitly required,
0.1.1
Following getter methods are added to [Cuase].
Cause::message()
Cuase::cause()
0.1.0
Initial Version
License
The MIT License (MIT)
Copyright (c) 2021 msr1k