Strongly typed routes for Rust

Overview

routetype

Rust

This repository is a work in progress, experimental exploration of strongly typed routing in Rust. It follows my previous work with Yesod in Haskell.

What's a strongly typed route?

With strongly typed routes, you have a single enum (or, in Haskell, ADT) that represents all potentially valid URLs in your web application. This type has parse and render functions, typically automatically generated by metaprogramming to avoid boilerplate errors. Entry to your application starts by calling that parse function to generate a value of this type. Instead of using string interpolation to generate links within your application, you use the render function.

Why would I want strongly typed routes?

There are a few advantages:

  • If you change the structure of your routes, generated code automatically updates.
  • More strongly, if you modify the parameters to your routes, existing code will fail to compile, and force you to update code appropriately.
    • In my opinion, this is the single greatest strength of a strongly typed codebase: common mistakes are converted into compile time errors, and the compiler can tell you exactly what you need to fix.
  • It can be far less tedious to generate URLs this way.
  • There's one central data type you can reference to see all of the different parts of your application.

What does this project consist of?

This is a work in progress, but for now it includes:

  • routetype
    • Helper functions for parsing paths and query strings, properly supporting URL decoding and corner cases like "query string keys without values," e.g. ?foo&bar&baz
    • A Route trait for strongly typed routes
  • routetype-derive: A derive macro for the Route type. This is exported automatically from routetype.
  • routetype-warp: A few Filters for parsing and dispatching impls of Route

What's coming next?

Possibly nothing. Possibly:

  • Building out additional support for Warp
  • Adding support for other frameworks like actix
  • Adding a lower level Hyper-specific binding
    • This likely would come with other helper functions to build out a microframework for simple apps
  • Actually releasing what's already here to crates.io!
  • Support multipath pieces, e.g. a trailing Vec of Strings
  • Support embedding other routes within this route, which may simply rely on the multipath concept

If this is interesting, and you'd like to be a part, jump in! No guarantees on anything, but issues, PRs, and direct messages anywhere about your interest in the project are more likely to push me into turning this into something real.

You might also like...
Astronomical algorithms in Rust

astro-rust Contents API Docs About Usage Contributing References About astro-rust is a library of advanced astronomical algorithms for the Rust progra

A Rust library for calculating sun positions

sun A rust port of the JS library suncalc. Install Add the following to your Cargo.toml [dependencies] sun = "0.2" Usage pub fn main() { let unixti

Macro for Python-esque comprehensions in Rust

Cute Macro for Python-esque list comprehensions in Rust. The c! macro implements list and hashmap comprehensions similar to those found in Python, all

Language Integrated Query in Rust.

Linq in Rust Language Integrated Query in Rust (created by declarative macros). Inspired by LINQ in .NET. What's LINQ This project is under developmen

A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

A Rust macro for writing regex pattern matching.

regexm A Rust macro for writing regex pattern matching.

Simple ray tracer written in Rust
Simple ray tracer written in Rust

Simple ray tracer written in Rust from scratch I've just finished my first semester at the Faculty of Applied Mathematics and Computer Science at the

A high level diffing library for rust based on diffs
A high level diffing library for rust based on diffs

Similar: A Diffing Library Similar is a dependency free crate for Rust that implements different diffing algorithms and high level interfaces for it.

A reactive DOM library for Rust in WASM

maple A VDOM-less web library with fine-grained reactivity. Getting started The recommended build tool is Trunk. Start by adding maple-core to your Ca

Owner
Michael Snoyman
I'm a Haskeller, I work on Yesod, Conduit, Stack, Stackage, and many others. VP of Engineering at FP Complete (@fpco).
Michael Snoyman
Create virtual serial ports, connect them to physical serial ports, and create routes between them all.

Virtual Serial Port Router (vsp-router) Create virtual serial ports, connect them to physical serial ports, and create routes between them all. vsp-ro

Rob Donnelly 3 Nov 24, 2022
k-mer counter in Rust using the rust-bio and rayon crates

krust is a k-mer counter written in Rust and run from the command line that will output canonical k-mers and their frequency across the records in a f

null 14 Jan 7, 2023
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

null 255 Dec 30, 2022
Aws-sdk-rust - AWS SDK for the Rust Programming Language

The AWS SDK for Rust This repo contains the new AWS SDK for Rust (the SDK) and its public roadmap. Please Note: The SDK is currently released as a dev

Amazon Web Services - Labs 2k Jan 3, 2023
Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

Jet Li 54 Dec 23, 2022
A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator

tmux-thumbs A lightning fast version of tmux-fingers written in Rust for copy pasting with vimium/vimperator like hints. Usage Press ( prefix + Space

Ferran Basora 598 Jan 2, 2023
A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

GB 314 Dec 18, 2022
Rust mid-level IR Abstract Interpreter

MIRAI MIRAI is an abstract interpreter for the Rust compiler's mid-level intermediate representation (MIR). It is intended to become a widely used sta

Facebook Experimental 793 Jan 2, 2023
Migrate C code to Rust

C2Rust helps you migrate C99-compliant code to Rust. The translator (or transpiler) produces unsafe Rust code that closely mirrors the input C code. T

Immunant 3k Jan 8, 2023
C to Rust translator

Corrode: Automatic semantics-preserving translation from C to Rust This program reads a C source file and prints an equivalent module in Rust syntax.

Jamey Sharp 2.1k Dec 14, 2022