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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! This module provides macros that add syntactic sugar for common operations.
//!
//! Note that some macros are implemented as proc macros, which can be found in
//! the [`rubedo-macros`](https://crates.io/crates/rubedo-macros) crate.
// Modules
// Packages
pub use ip;
// Macros
// s!
/// Converts a [`str`] string literal to an owned [`String`].
///
/// This macro provides syntactic sugar to convert static [`str`] instances to
/// [`String`]s - this saves having to do `"foo".to_owned()` or
/// `String::from("foo")`.
///
/// It will also convert any other type that implements the [`ToString`] trait
/// to a [`String`] — providing that it is passed in as a variable or some kind
/// of expression, and not as a literal. That's because, at present, there is no
/// way for the macro to tell the difference between [`str`] literals and other
/// literals such as numbers, and as a result it will call `to_owned()` on them
/// and give a non-[`String`] result, which will not match expectations. For
/// this reason, this ability is not as useful as the [`str`] behaviour, and it
/// does not provide a consistent interface for converting to [`String`]s (and
/// nor is it intended to).
///
/// When converting from other types it is likely best to use the standard
/// conversion functions directly, to avoid confusion, and so the recommendation
/// is to only use this macro as shorthand for converting [`str`] instances.
///
/// The inspiration for this macro comes from the [`velcro`](https://crates.io/crates/velcro)
/// crate, which provides a range of macros for creating collections, building
/// on the built-in [`vec!`] macro.
///
/// # Examples
///
/// ```
/// use rubedo::sugar::s;
///
/// assert_eq!(s!("foo"), "foo");
/// assert_eq!(s!("foo"), "foo".to_owned());
/// assert_eq!(s!("foo"), "foo".to_string());
/// assert_eq!(s!("foo"), String::from("foo"));
/// ```
///
/// # See also
///
/// * [`str`]
/// * [`String`]
/// * [`ToString`]
/// * [`vec!`]
/// * [`velcro`](https://crates.io/crates/velcro)
///
pub use s;
// variants!
/// Allows shorthand for referring to multiple variants of the same enum.
///
/// This macro provides syntactic sugar to specify multiple enum variants using
/// reduced syntax, making such usage more concise, and easier to read.
///
/// It supports lists of variants separated by commas. It would be nice to also
/// use the boolean OR operator for use in matches, but this is not possible at
/// present, as match arms must be explicit, and cannot rely on expressions.
///
/// This macro returns the variants as a [`Vec`], and there is an alternative
/// macro, [`variants_hashset!`], which returns a [`HashSet`](std::collections::HashSet)
/// instead.
///
/// It is is exported as `vv!` (meaning "variants vector") as well as
/// `variants!`, to allow for more concise usage.
///
/// # Examples
///
/// ```
/// use rubedo::sugar::vv;
///
/// #[derive(Copy, Clone, Debug, Eq, PartialEq)]
/// enum Foo {
/// Bar,
/// Baz,
/// Qux,
/// }
///
/// assert_eq!(vv![ Foo: Bar, Baz, Qux ], vec![ Foo::Bar, Foo::Baz, Foo::Qux ]);
/// assert_eq!(vv![ Foo: ], vec![]);
/// ```
///
/// # See also
///
/// * [`variants_hashset!`]
///
pub use variants;
pub use variants as vv;
// variants_hashset!
/// Allows shorthand for referring to multiple variants of the same enum.
///
/// This macro is the same as [`variants!`], but returns a [`HashSet`](std::collections::HashSet)
/// instead of a [`Vec`]. For more information, see the documentation for
/// [`variants!`].
///
/// It is is exported as `vh!` (meaning "variants hashset") as well as
/// `variants_hashset!`, to allow for more concise usage.
///
/// # Examples
///
/// ```
/// use rubedo::sugar::vh;
/// use std::collections::HashSet;
///
/// #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
/// enum Foo {
/// Bar,
/// Baz,
/// Qux,
/// }
///
/// assert_eq!(vh![ Foo: Bar, Baz, Qux ], HashSet::from([ Foo::Bar, Foo::Baz, Foo::Qux ]));
/// assert_eq!(vh![ Foo: ], HashSet::from([]));
/// ```
///
/// # See also
///
/// * [`variants!`]
///
pub use variants_hashset;
pub use variants_hashset as vh;