Crates.io | lightning-path |
lib.rs | lightning-path |
version | 1.0.2 |
source | src |
created_at | 2024-06-18 01:51:20.275234 |
updated_at | 2024-06-18 02:06:14.320412 |
description | Route Recognizer library for lightning-fast matching |
homepage | |
repository | |
max_upload_size | |
id | 1275033 |
size | 21,654 |
This project serves as a study into the concept of Non-deterministic Finite Automata (NFA) and its applications in route recognition. By leveraging the already existing route-recognizer library, this project aims to delve into the practical implementation and benefits of using NFA for dynamic route handling. The route-recognizer library provides a solid foundation for exploring these concepts in Rust, demonstrating how NFAs can be used to efficiently match and manage routes.
Lightning-Path is a high-performance route recognizer library for Rust, designed to match URL patterns efficiently using the Non-deterministic Finite Automaton (NFA) concept. It allows you to define routes and quickly determine which route matches a given URL path, making it ideal for web frameworks and other applications requiring fast and reliable routing.
use lightning_path::Router;
fn main() {
let mut router = Router::new();
router.add("/home", "Home");
router.add("/about", "About");
router.add("/contact", "Contact");
let m = router.recognize("/home").unwrap();
assert_eq!(*m.handler, Some("Home"));
}
use lightning_path::Router;
fn main() {
let mut router = Router::new();
router.add("/user/:id", "User");
router.add("/post/:id", "Post");
let m = router.recognize("/user/123").unwrap();
assert_eq!(*m.handler, Some("User"));
assert_eq!(m.params.find("id"), Some("123"));
}
use lightning_path::Router;
fn main() {
let mut router = Router::new();
router.add("/fs/*path", "fs");
let m = router.recognize("/fs/random-file-path").unwrap();
assert_eq!(*m.handler, "fs");
assert_eq!(m.params.find("path"), Some("random-file-path"));
}