Skip to main content

walk_files_bounded_count

Function walk_files_bounded_count 

Source
pub fn walk_files_bounded_count(
    dir: &Path,
    extension: &str,
    max_files: usize,
) -> Result<Vec<PathBuf>, SsgError>
Expand description

Recursively collects files matching extension, capped at max_files. Provides with_context on the underlying read_dir failure.

Used by livereload (50 000 file cap) and similar fast-path walkers that need a bounded latency upper bound.

ยงExamples

use ssg::walk::walk_files_bounded_count;
use tempfile::tempdir;
use std::fs;

let dir = tempdir().unwrap();
fs::write(dir.path().join("a.md"), "").unwrap();
fs::write(dir.path().join("b.md"), "").unwrap();
let v = walk_files_bounded_count(dir.path(), "md", 1).unwrap();
assert_eq!(v.len(), 1);