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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/// The parsing utilities in `cu` provides wrapper to the std library
/// for parsing common data, such as different radix for numbers,
/// and support for common formats like `json`, `yaml` and `toml`.
///
/// Everything only works with UTF-8.
///
/// The entry points to parsing are [`cu::parse::<T>`](crate::parse), and `"...".parse_to::<T>()`.
/// Use whichever is more readable or preferrable at the call sites.
///
/// ```rust
/// # use pistonite_cu as cu;
/// use std::path::PathBuf;
/// use cu::pre::*;
///
/// # fn main() -> cu::Result<()> {
/// # use pistonite_cu as cu;
/// // bool: empty string, 0, 1, "true", or "false", case-insensitive
/// let x = cu::parse::<bool>("0")?;
/// assert_eq!(x, false);
///
/// // numbers: hex, oct and binary are supported with 0x, 0b, and 0o prefix
/// let x = cu::parse::<u32>("0")?;
/// assert_eq!(x, 0);
/// let x = cu::parse::<i32>("-123")?;
/// assert_eq!(x, -123);
/// let x = cu::parse::<usize>("0x123")?;
/// assert_eq!(x, 0x123);
///
/// // .parse_to() can be used when chaining,
/// // instead of wrapping in cu::parse or use a temporary variable.
/// let _x = "imagine some long chaining is used to get this value"
/// .parse_to::<PathBuf>()?;
/// # Ok(()) }
/// ```
///
/// If the value is owned, you can use `parse_owned` instead of `parse`.
/// For readers, use [`cu::read`] or [`cu::co_read`] for async readers.
///
/// # From Owned and Read
/// When possible, implementation of parsing from a `io::Read` is provided
/// for optimization (for example for `json` inputs using `serde_json::from_reader`).
///
/// Async read is also supported, however, at the time of writing,
/// the inputs are first read into a buffer asynchronously, then
/// parsed synchronously from the buffer.
///
/// # Remote Derive
/// Common types are implemented in this library. You can derive
/// this trait by using the [`Parse`] derive macro
/// for any type that implements [`FromStr`].
///
/// # Common Formats
/// When `json`/`yaml`/`toml` features are enabled, the respective
/// module will be included in the prelude.
/// See [`json`]/[`yaml`]/[`toml`] for more details.
///
/// [`FromStr`]: std::str::FromStr
/// [`Parse`]: macro@crate::Parse
/// [`json`]: module@crate::json
/// [`yaml`]: module@crate::yaml
/// [`toml`]: module@crate::toml
/// [`cu::read`]: crate::read
/// [`cu::co_read`]: crate::co_read
/// the `.parse_to` function.
///
/// See [`Parse`](trait@Parse)
/// Parse a value from a `&str`.
///
/// See [`Parse`](trait@Parse)
/// Parse a value from a `String`.
///
/// See [`Parse`](trait@Parse)
/// Parse a value from a `std::io::Read`.
///
/// See [`Parse`](trait@Parse)
/// Parse a value from a `tokio::io::AsyncRead`.
///
/// See [`Parse`](trait@Parse)
pub async