Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::fs::{read_dir, File};
- use std::io::prelude::*;
- use std::io::{self, BufReader};
- use std::path::{Path, PathBuf};
- fn read_all<P: AsRef<Path>>(path: P) -> io::Result<HashMap<PathBuf, usize>> {
- let dir = read_dir(path)?;
- dir.map(|entry| {
- entry.and_then(|entry| {
- File::open(entry.path()).map(|file| {
- let lines = BufReader::new(file).lines().count();
- (entry.path(), lines)
- })
- })
- }).collect::<io::Result<HashMap<_, _>>>()
- }
- fn main() {
- let hash_map = read_all("etc/boilerpipe").unwrap();
- }
Add Comment
Please, Sign In to add comment