INNER CODE UNIT · Rust

get_segments

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

    pub fn get_segments(p: &str) -> Vec<&str> {
        let stripped = p.strip_prefix('/').unwrap_or(p);
        stripped.split('/').collect::<Vec<&str>>()
    }
}

use utils::get_segments;

lazy_static! {
        // Dynamic Route - /api/[id]
        static ref DYNAMIC_ROUTE_REGEX: Regex = Regex::new(r"\[[^/\.]+\]").unwrap();
        // Catch-all Route - /api/[...slug]
        static ref DYNAMIC_CATCH_ALL_REGEX: Regex = Regex::new(r"\[\.{3}\S+\]").unwrap();
        // Optional catch-all Route - /api/[[...slug]]
        static ref DYNAMIC_OPTIONAL_CATCH_ALL_REGEX: Regex = Regex::new(r"\[{2}\.{3}\S+\]{2}").unwrap();
}

#[derive(Debug, PartialEq, PartialOrd)]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…