#validation #structure

fsvalidator

A file structure validator

1 unstable release

Uses new Rust 2024

new 0.1.1 May 1, 2025
0.1.0 Apr 30, 2025

#519 in Filesystem

30 downloads per month

MIT/Apache

15KB
359 lines

File Structure Validator

A Rust library for validating real filesystem directories against a declarative, strongly-typed schema. Useful for enforcing project structure, data ingestion layout, or configuration rules.

Features

  • Strongly-typed node model with Literal and regex Pattern matching.
  • Supports nested directory/file trees.
  • Shared template support via references.
  • Optional validation strictness (required, allow_defined_only).
  • Built-in validation with informative errors.

Example

use validator::{Node, DirNode, FileNode, NodeName};
use std::path::Path;

let schema = DirNode::new(
    NodeName::Literal("project".into()),
    vec![
        FileNode::new(NodeName::Pattern(r".*\\.md$".into()), true),
        DirNode::new(NodeName::Pattern(r"src_.*".into()), vec![], true, false),
    ],
    true,
    false,
);

schema.validate(Path::new("."))?;

Model Overview

enum Node {
    Dir(Rc<RefCell<DirNode>>),
    File(Rc<RefCell<FileNode>>),
}

struct DirNode {
    name: NodeName,
    children: Vec<Node>,
    required: bool,
    allow_defined_only: bool,
}

struct FileNode {
    name: NodeName,
    required: bool,
}

enum NodeName {
    Literal(String),
    Pattern(String), // Regex
}

Use Cases

  • Project layout enforcement
  • Data pipeline input verification
  • Config tree validation
  • Template-based directory reuse

Installation

Add to Cargo.toml:

[dependencies]
validator = { fsvalidator = "0.1.0" }

License

MIT

Dependencies

~2.5–4MB
~76K SLoC