taskdn-rust
Rust library for parsing, querying, and manipulating Taskdn task files.
Overview
This is the core SDK that powers the Taskdn ecosystem. It provides:
- Parsing - Read markdown files with YAML frontmatter into typed entities
- Querying - Filter tasks, projects, and areas by status, dates, assignments
- CRUD Operations - Create, read, update, and delete entities with automatic timestamp management
- Validation - Check files against the Taskdn specification
- Round-trip Preservation - Unknown frontmatter fields are preserved when writing
- File Watching - Process file system events or use built-in watcher
Installation
Add to your Cargo.toml:
[]
= "0.1"
For file watching support:
[]
= { = "0.1", = ["watch"] }
Quick Start
use ;
use PathBuf;
Usage Examples
Creating Tasks
use ;
use NaiveDate;
// Simple task (defaults to Inbox status)
let task = new;
// Task with all options
let task = new
.with_status
.with_due
.with_scheduled
.in_project
.in_area
.with_body;
Querying Tasks
use ;
use NaiveDate;
// By status
let ready = sdk.list_tasks?;
let active = sdk.list_tasks?;
// By assignment
let project_tasks = sdk.list_tasks?;
let orphan_tasks = sdk.list_tasks?;
// By dates
let today = from_ymd_opt.unwrap;
let overdue = sdk.list_tasks?;
let due_soon = sdk.list_tasks?; // next 7 days
let visible = sdk.list_tasks?;
// Preset filters
let inbox = sdk.list_tasks?;
let available = sdk.list_tasks?;
Updating Tasks
use ;
// Update specific fields
sdk.update_task?;
// Clear optional fields
sdk.update_task?;
// Convenience methods for status transitions
sdk.complete_task?; // Sets status to Done, sets completed_at
sdk.drop_task?; // Sets status to Dropped, sets completed_at
sdk.start_task?; // Sets status to InProgress
sdk.block_task?; // Sets status to Blocked
Working with Projects
use ;
// Create a project
let path = sdk.create_project?;
// Query projects
let active = sdk.list_projects?;
let work_projects = sdk.list_projects?;
// Get tasks belonging to a project
let tasks = sdk.get_tasks_for_project?;
Working with Areas
use ;
// Create an area
let path = sdk.create_area?;
// Query areas
let active = sdk.list_areas?;
// Get all entities in an area (direct + via project)
let tasks = sdk.get_tasks_for_area?;
let projects = sdk.get_projects_for_area?;
File Watching
Process file changes manually:
use ;
// When your file watcher reports a change
if let Some = sdk.process_file_change?
Or use the built-in watcher (requires watch feature):
use ;
use Duration;
let = new?;
// Events arrive on the receiver channel
for event in receiver
Validation
// Validate a single task
let warnings = sdk.get_task_warnings?;
for warning in warnings
// Validate all tasks
let result = sdk.validate_all_tasks;
for in &result.warnings
Parsing Without SDK
Parse content directly without file I/O:
use ParsedTask;
let content = r#"---
title: My Task
status: ready
created-at: 2025-01-01
updated-at: 2025-01-02
---
Task body content.
"#;
let parsed = parse?;
println!;
// Convert to full Task by adding a path
let task = parsed.with_path;
Performance
Target benchmarks (5000 files):
| Operation | Target | Description |
|---|---|---|
| Single file parse | <1ms | Parse one markdown file |
| Full vault scan | 200-500ms | List all tasks with parallel parsing |
| Query (in-memory) | <5ms | Filter already-loaded tasks |
The SDK uses rayon for parallel file parsing during scans.
Development
Prerequisites
- Rust 1.70+ (2021 edition)
- just (optional, for task runner)
Commands
Project Structure
src/
├── lib.rs # Public API, SDK entry point
├── config.rs # Configuration types
├── error.rs # Error types (thiserror)
├── types/ # Entity types (Task, Project, Area)
│ ├── task.rs # Task entity, NewTask, TaskUpdates
│ ├── project.rs # Project entity, NewProject, ProjectUpdates
│ ├── area.rs # Area entity, NewArea, AreaUpdates
│ ├── datetime.rs # DateTimeValue (preserves format)
│ └── reference.rs # FileReference (WikiLink, path)
├── filter.rs # TaskFilter, ProjectFilter, AreaFilter
├── parser.rs # Frontmatter parsing (gray_matter)
├── writer.rs # File writing with field preservation
├── operations/ # SDK method implementations
│ ├── tasks.rs # Task CRUD operations
│ ├── projects.rs # Project CRUD operations
│ ├── areas.rs # Area CRUD operations
│ └── validation.rs# Validation operations
├── events.rs # VaultEvent, file change processing
├── watcher.rs # FileWatcher (watch feature)
└── validation.rs # ValidationWarning types
Testing
Integration tests use a disposable copy of the demo vault:
License
MIT