← LeaderboardThe Skill Leaderboard

rust-globset-path-separators

Match direct children and recursive paths explicitly with Rust globset. Check literal separators and verify both patterns against native Windows paths.

Published by sickn33 ↗sickn33/agentic-awesome-skills

Try your first task

A source-grounded starter task has not been verified for this skill yet.

SKILL.md

name: rust-globset-path-separatorsdescription: Match direct children and recursive paths explicitly with Rust globset. Check literal separators and verify both patterns against native Windows paths.category: developmentrisk: criticalsource: selfsource_type: selfdate_added: "2026-12-03"author: ShianMiketags: [rust, globset, path, glob, windows]

Rust globset path separators

When to Use

  • A Rust asset selector using assets/*.png unexpectedly includes images in nested folders.
  • A migration from another glob tool changes whether * and ? can cross path separators.
  • One configuration must express both direct-child and recursive selection.

Prerequisites

  • Locate the glob compilation and the path representation at the matcher call.
  • Identify the base directory, the intended case policy, and where the operation enumerates candidates.
  • Verify the installed globset version and options. The example uses 0.4.21 and Windows-native PathBuf values.

1. Compare the configured grammar with the intended scope

  1. Write down which candidate paths should match within one directory and in subdirectories. Include a nearby directory with a similar name.
  2. Inspect the actual builder. Globset allows * and ? to match across separators by default.
  3. Check the path passed to the matcher. A root-relative pattern should receive the path relative to the same root. Test the actual input if another layer normalizes paths.
  4. Trace where matches are consumed. A correct predicate can still produce the wrong result if the walker starts in the wrong tree or includes a different set of candidates.

2. Make crossed separators explicit

  • Compile the one-level predicate with GlobBuilder::new(pattern).literal_separator(true).build() so ordinary wildcards stay within a path component.
  • Use an explicit recursive form such as assets/**/*.png when nested directories belong in the match. Verify whether the form also includes direct children.
  • Use forward slashes in the stored patterns when the same set must work across platforms. Pass native paths to the matcher and inspect backslash escape and case settings when importing patterns from another tool.
  • Surface invalid patterns as configuration errors through the caller's existing error path. Compile the matcher when the pattern set changes and reuse it across candidates.

3. Verify the selected file list

  1. Compare the direct-child and recursive forms on the same inputs. Include a direct match, a nested match, a different extension, and a similar directory prefix.
  2. Assert the selected paths or record labels instead of only the count. Build candidates with Path::join if production sends native paths.
  3. Include both case variants or escaped characters when the configuration permits them. Use the actual pattern policy.
  4. Check the end-to-end walker and consumer before changing a real build or packaging filter.

Example

Distinguish direct and recursive assets shows a direct-child glob mistakenly selecting a nested image. Enabling literal separators confines the direct matcher while the recursive matcher still selects both images.

Limitations

  • The fixture exercises globset matching on four in-memory paths. Filesystem traversal, links, case variants, and imported gitignore or shell rules need their own tests.
  • Matching a path string does not establish filesystem containment. Establish the walk root and apply any required symlink policy at the traversal boundary.
  • Multi-pattern include and exclude precedence belongs to the caller or rule engine.

Safety and Side Effects

The fixture opens no files. A real selector can affect which items are packaged or processed. Verify the selected list against disposable or synthetic inputs before applying a change.

Related Skills and Documentation

rust-globset-path-separators by sickn33 · The Skill Leaderboard