tree-type-proc-macro 0.2.0

Procedural macros for tree-type crate
Documentation
use tempfile::TempDir;
use tree_type_proc_macro::tree_type;

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Key(String);

impl std::fmt::Display for Key {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for Key {
    type Err = std::convert::Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Key(s.to_string()))
    }
}

tree_type! {
    TestRoot {
        tasks/ {
            [id: String]/ as TaskDir {
                metadata("metadata.toml")
            }
            [key: Key]/ as KeyDir {
            }
        }
    }
}

#[test]
fn test_dynamic_id_compiles() {
    let tempdir = TempDir::new().unwrap();
    let root = TestRoot::new(tempdir.path()).unwrap();

    // Should compile - verifies dynamic ID parsing works
    let tasks = root.tasks();
    assert_eq!(tasks.as_path(), tempdir.path().join("tasks"));
}

#[test]
fn test_dynamic_id_manual_access() {
    let tempdir = TempDir::new().unwrap();
    let root = TestRoot::new(tempdir.path()).unwrap();

    // Create tasks directory
    root.create_all().unwrap();

    // Use parameterized access to get specific task
    let task1 = root.tasks().id("task-1");

    // Create the task directory
    task1.create_all().unwrap();

    // Verify it exists
    assert!(task1.exists());
    assert_eq!(task1.as_path(), tempdir.path().join("tasks/task-1"));
}

#[test]
fn test_dynamic_id_non_string_key() {
    let tempdir = TempDir::new().unwrap();
    let root = TestRoot::new(tempdir.path()).unwrap();

    // Create tasks directory
    root.create_all().unwrap();

    // Use parameterized access to get specific task
    let key_alpha = root.tasks().key(Key("key-alpha".to_string()));

    // Create the task directory
    key_alpha.create_all().unwrap();

    // Verify it exists
    assert!(key_alpha.exists());
    assert_eq!(key_alpha.as_path(), tempdir.path().join("tasks/key-alpha"));
}