pub mod act;
pub mod io;
pub mod iter;
mod orderedmap;
pub mod strings;
pub mod prelude {
pub use super::act::*;
pub use super::io::*;
pub use super::iter::any::*;
pub use super::iter::collections::*;
pub use super::iter::convert::*;
pub use super::iter::groupby::*;
pub use super::iter::sort::*;
pub use super::iter::unique::*;
pub use super::iter::*;
pub use super::strings::*;
}
#[cfg(test)]
mod tests {
use std::{
collections::{HashMap, HashSet},
fs::File,
io::{BufRead, BufReader},
};
use crate::prelude::*;
#[test]
fn readme() {
let a1 = [1, 2, 3].iter().map(|a| a * 2).to_vec();
let b1 = [1, 2, 3].iter().map(|a| a * 2).to_hashset();
let c1 = [(1, 2), (3, 4)].into_iter().to_hashmap();
let a2 = [1, 2, 3].iter().map(|a| a * 2).collect::<Vec<_>>();
let b2 = [1, 2, 3].iter().map(|a| a * 2).collect::<HashSet<_>>();
let c2 = [(1, 2), (3, 4)].into_iter().collect::<HashMap<_, _>>();
assert_eq!(a1, a2);
assert_eq!(b1, b2);
assert_eq!(c1, c2);
let mut a = HashSet::<u8>::from_iter([1, 2, 3]).into_vec();
let mut b = HashSet::<u8>::from_iter([1, 2, 3])
.into_iter()
.collect::<Vec<_>>();
a.sort();
b.sort();
assert_eq!(a, b);
let vec = vec![1];
assert_eq!(
if vec.any() { true } else { false },
if !vec.is_empty() { true } else { false }
);
}
#[test]
#[should_panic]
fn readme_io() {
let path = "/tmp/test.txt";
for line in BufReader::new(File::open(&path).unwrap()).lines() {
let line = line.unwrap();
println!("{line}");
}
let file = File::open(&path);
match file {
Ok(file) => {
for line in BufReader::new(file).lines() {
match line {
Ok(line) => println!("{line}"),
Err(_) => panic!("Error"),
}
}
}
Err(_) => panic!("Error"),
}
for line in lines(path) {
println!("{line}");
}
}
}