1pub mod act;
2pub mod io;
3pub mod iter;
4mod orderedmap;
5pub mod strings;
6
7pub mod prelude {
8 pub use super::act::*;
9 pub use super::io::*;
10 pub use super::iter::any::*;
11 pub use super::iter::collections::*;
12 pub use super::iter::convert::*;
13 pub use super::iter::groupby::*;
14 pub use super::iter::sort::*;
15 pub use super::iter::unique::*;
16 pub use super::iter::*;
17 pub use super::strings::*;
18}
19
20#[cfg(test)]
21mod tests {
22 use std::{
23 collections::{HashMap, HashSet},
24 fs::File,
25 io::{BufRead, BufReader},
26 };
27
28 use crate::prelude::*;
29 #[test]
30 fn readme() {
31 let a1 = [1, 2, 3].iter().map(|a| a * 2).to_vec();
33 let b1 = [1, 2, 3].iter().map(|a| a * 2).to_hashset();
34 let c1 = [(1, 2), (3, 4)].into_iter().to_hashmap();
35
36 let a2 = [1, 2, 3].iter().map(|a| a * 2).collect::<Vec<_>>();
37 let b2 = [1, 2, 3].iter().map(|a| a * 2).collect::<HashSet<_>>();
38 let c2 = [(1, 2), (3, 4)].into_iter().collect::<HashMap<_, _>>();
39 assert_eq!(a1, a2);
40 assert_eq!(b1, b2);
41 assert_eq!(c1, c2);
42
43 let mut a = HashSet::<u8>::from_iter([1, 2, 3]).into_vec();
45 let mut b = HashSet::<u8>::from_iter([1, 2, 3])
46 .into_iter()
47 .collect::<Vec<_>>();
48 a.sort();
49 b.sort();
50 assert_eq!(a, b);
51 let vec = vec![1];
53 assert_eq!(
54 if vec.any() { true } else { false },
55 if !vec.is_empty() { true } else { false }
56 );
57 }
58
59 #[test]
60 #[should_panic]
61 fn readme_io() {
62 let path = "/tmp/test.txt";
64 for line in BufReader::new(File::open(&path).unwrap()).lines() {
65 let line = line.unwrap();
66 println!("{line}");
67 }
68
69 let file = File::open(&path);
70 match file {
71 Ok(file) => {
72 for line in BufReader::new(file).lines() {
73 match line {
74 Ok(line) => println!("{line}"),
75 Err(_) => panic!("Error"),
76 }
77 }
78 }
79 Err(_) => panic!("Error"),
80 }
81
82 for line in lines(path) {
83 println!("{line}");
84 }
85 }
86}