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
//! Syntax sugar to make your Rust life more sweet.
//!
//! # Usage
//! ```rust
//! use sugar::*;
//! ```
//! # Sugars
//!
//! ## Collections construct
//! ```
//! use sugar::*;
//!
//! // vec construction
//! let v = vec![1, 2, 3];
//!
//! // vec of boxed value
//! let vb = vec_box![1, 2, 3];
//!
//! // hashmap construction
//! let hm = hashmap!{
//! 1 => 2,
//! 2 => 3,
//! 3 => 4,
//! };
//!
//! // list comprehension
//! let vb2 = c![Box::new(i), for i in 1..4];
//! assert_eq!(vb, vb2);
//!
//! // hashmap comprehension
//! let hm2 = c![i => i + 1, for i in 1..4];
//! assert_eq!(hm, hm2);
//! ```
//!
//! * `vec_box!` is reexported from [`vec_box`](https://docs.rs/vec_box)
//! * `hashmap!` and related macros are reexported from [`maplit`](https://docs.rs/maplit) crate
//! * `c!` list comprehension macro is reexported from [`cute`](https://docs.rs/cute) crate
//!
//! ## Hashmap: clone a value of speical key.
//!
//! ```
//! use sugar::*;
//!
//! let hm = hashmap! {
//! 1 => "1".to_owned(),
//! 2 => "2".to_owned(),
//! };
//!
//! let s = {
//! hm.get_clone(&1)
//! };
//!
//! assert_eq!(s.unwrap(), "1".to_owned());
//!
//! ```
//!
//! ## Result: ignore Result's OK value
//! ```
//! use sugar::SResultExt;
//!
//! fn do_work1() -> Result<i32, String> {
//! Ok(1)
//! }
//!
//! fn do_work2() -> Result<(), String> {
//! // I don't care about the result's Ok value
//! do_work1()
//! .drop_value()
//! }
//!
//! do_work2();
//! ```
//!
//! ## max! and min! macros
//! ```
//! use sugar::*;
//!
//! assert_eq!(max!(3, 1, 2, 7, 0), 7);
//! assert_eq!(min!(3, 1, 2, 7, 0), 0);
//! ```
//! * `max!` and `min!` reexported from [`min_max_macros`](https://docs.rs/min_max_macros)
//!
//!
//! ## Chained comparison
//! ```
//! use sugar::*;
//!
//! fn return_2() -> i32 {
//! return 2;
//! }
//!
//! assert_eq!(cmp!(1, < 2, < 3), true);
//! assert_eq!(cmp!(1, <= 2, <= 3), true);
//! assert_eq!(cmp!(1, <= 2, <= 3, != 4), true);
//!
//! // return_2 will not be called
//! assert_eq!(cmp!(2, < 1, < 3, < return_2()), false);
//!
//! // return_2 will be called once
//! assert_eq!(cmp!(1, < return_2(), <= 2), true);
//! ```
extern crate maplit;
extern crate cute;
extern crate vec_box;
extern crate min_max_macros;
pub use SResultExt;
pub use SHashMapExt;
pub use *;
pub use *;