Datapath: type-safe structured paths
Provides simple macros and utilities for type-safe structured paths. This is intended for use with S3 and duckdb hive partitions, or simple S3 paths for lancedb.
Basic Usage
use ;
use Uuid;
/// Define a datapath pattern
datapath!
// Create a datapath instance
let path = CaptureRaw ;
println!; // "capture/user_id=<uuid>/ts=1234567890/raw/2.0"
let file = path.with_file;
println!; // "capture/user_id=<uuid>/ts=1234567890/raw/2.0/data.json"
let parsed = parse;
match parsed
Schema Associations
Associate datapaths with schema types for type-safe data handling:
use ;
datapath!
// EventPath now implements SchemaDatapath
// EventPath::Schema == UserEvent
Pattern Introspection and Wildcards
Access the pattern string and work with wildcarded paths:
use ;
use Uuid;
datapath!
// Access the pattern string
// (use for logging/debug)
assert_eq!;
// Convert to/from tuples
let metrics = Metrics ;
let tuple = metrics.clone.to_tuple;
assert_eq!;
let recreated = from_tuple;
assert_eq!;
assert_eq!;
// Create wildcarded paths for querying
let all_services = from_wildcardable;
assert_eq!;
Examples
use ;
;
datapath!
Constant-Only Paths
Paths with no typed fields work correctly with empty tuples:
use ;
datapath!
// PATTERN works for constant-only paths
assert_eq!;
// Tuple type is unit ()
let empty_tuple = ConstantPath .to_tuple;
assert_eq!;
let path = from_tuple;
assert_eq!;
// from_wildcardable also works (no wildcards possible)
let path_str = from_wildcardable;
assert_eq!;