1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A tiny crate for error handling. It is able to convert items of the
//! [`Error`](https://doc.rust-lang.org/std/error/trait.Error.html) trait into
//! their messages, allowing for easy propagation.
//!
//! # Examples
//!
//! ```rust
//! use tiny_error::ErrorMessage;
//!
//! use std::{
//! env,
//! fs,
//! path::PathBuf,
//! };
//!
//! fn main() -> Result<(), ErrorMessage> {
//! // Text when failed:
//! // Error: Invalid input
//! // Correct Usage: `[crate_name] example/file/path.txt`
//! let path = get_path()?;
//! // Text when failed:
//! // Error: No such file or directory (os error 2)
//! let file = fs::read_to_string(path)?;
//!
//! Ok(())
//! }
//!
//! // Gets the first argument passed. If none or more were, returns an
//! // `ErrorMessage`.
//! fn get_path() -> Result<PathBuf, ErrorMessage> {
//! let mut args = env::args().skip(1);
//! let arg = args.next().filter(|_| args.next().is_none());
//!
//! arg
//! .map(|input| input.into())
//! .ok_or_else(|| ErrorMessage::new(
//! "Invalid input\n\
//! Correct Usage: `[crate_name] example/file/path.txt`"
//! ))
//! }
//! ```
use ;
/// The struct that holds the error message.
;