INNER CODE UNIT · Rust

cmp

vercel-community/rust · crates/vercel_runtime_router/src/lib.rs:43

    fn cmp(&self, other: &Self) -> Ordering {
        match self.kind {
            // Sort by length in descending order
            RouteKind::Static => match other.kind {
                RouteKind::Static => other.path.len().cmp(&self.path.len()),
                _ => Ordering::Less,
            },
            // Sort by segment length in descending order
            RouteKind::Dynamic => match other.kind {
                RouteKind::Static => Ordering::Greater,
                RouteKind::Dynamic => match self.segments {
                    Some(ref s) => match other.segments {
                        Some(ref o) => {
                            // If segments have equal length, sort by the position of the first dynamic segment
                            // This has to be done so `api/[id]/static` is matched before `api/[id]/[dynamic]`
                            if s.len() == o.len() {
                                let s_pos = s
                                    .iter()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…