turbopack_node/
route_matcher.rs

1use turbo_rcstr::RcStr;
2use turbo_tasks::{FxIndexMap, Vc};
3
4#[turbo_tasks::value]
5#[derive(Debug, Clone)]
6#[serde(untagged)]
7pub enum Param {
8    Single(RcStr),
9    Multi(Vec<RcStr>),
10}
11
12#[turbo_tasks::value(transparent)]
13#[derive(Debug, Clone)]
14pub struct Params(pub Option<FxIndexMap<RcStr, Param>>);
15
16/// Extracts parameters from a URL path.
17pub trait RouteMatcherRef {
18    /// Returns whether the given path is a match for the route.
19    fn matches(&self, path: &str) -> bool;
20
21    /// Returns the parameters extracted from the given path.
22    fn params(&self, path: &str) -> Params;
23}
24
25/// Extracts parameters from a URL path (Vc version)
26#[turbo_tasks::value_trait]
27pub trait RouteMatcher {
28    /// Returns whether the given path is a match for the route.
29    fn matches(self: Vc<Self>, path: RcStr) -> Vc<bool>;
30
31    /// Returns the parameters extracted from the given path.
32    fn params(self: Vc<Self>, path: RcStr) -> Vc<Params>;
33}