Skip to main content

datapath/
datapath.rs

1use std::{
2	fmt::{Debug, Display},
3	hash::Hash,
4};
5
6use crate::DatapathFile;
7
8pub trait Datapath
9where
10	Self: Send + Sync + 'static,
11	Self: Clone + Sized,
12	Self: Eq + PartialEq + Hash,
13	Self: Debug + Display,
14{
15	/// The exact pattern string passed to the macro that generated this struct
16	const PATTERN: &'static str;
17
18	/// A tuple of this path's parameter types, in the order they appear in the pattern
19	type Tuple;
20
21	/// [Datapath::Tuple], but each type is wrapped in a [crate::Wildcardable].
22	type WildcardableTuple;
23
24	fn from_tuple(tuple: Self::Tuple) -> Self;
25	fn to_tuple(self) -> Self::Tuple;
26
27	/// Return a string where wildcarded partitions are `*`.
28	fn from_wildcardable(tuple: Self::WildcardableTuple) -> String;
29
30	/// Returns a [DatapathFile] with the given file at this datapath
31	fn with_file(&self, file: impl Into<String>) -> DatapathFile<Self>;
32
33	/// Parse a string as this datapath with a (possibly empty-string)
34	/// file, returning `None` if this string is invalid.
35	fn parse(path: &str) -> Option<DatapathFile<Self>>;
36
37	/// Get the string value of the field with the given name,
38	/// if it exists.
39	fn field(&self, name: &str) -> Option<String>;
40}