#macro #web


Pack of macros for web-programming in Rust

2 releases (1 stable)

1.0.0 Sep 26, 2021
0.1.0 Sep 25, 2021

#170 in HTTP server

MIT license

96 lines


Pack of macros for web-programming in Rust

A simple package with attributes to bind function patterns to the framework actix-web.

fn index() {

turn into

async fn index() -> impl Responder {

There are 3 attributes in total


POST need set to POST request (There is also a special type for handling structs as post requests, which is actix_web::web::Form;)

#[derive(Deserialize)]  // (yea, use serde)
struct User {
    username: String,
    email: String,
    password: String

fn index_analyz(data: Post<User>) {
    println!("{:#?}", data);

SERVER set to main of your site

fn main() {
    HttpServer::new(|| {
    .bind(("", 8080))?

And a little with macros setting HttpResponce for the kind of response body.

#[template(path="../static/index.html")] // askama template render engine
struct MyPage {
    content: String

fn foo() {
    html!("<h1>html text!</h1>")
    load!("compile-time static load of html file use include_str! macro")
    template!(MyPage { content: "nice".to_string() })
    // expression of struct. implemented for .render() in askama engine

and a one function for parse urls with regex (must run in tokio runtime, what reimported in crate)

let prs; {
    let tokioRuntime = Runtime::new().unwrap();
    prs = tokioRuntime.spawn(parsing(
let prs = prs.unwrap();
println!("{:?}", prs);

Reimported crates

actix-web = "3"
regex = "1.5.4"
tokio = { version = "1", features = ["rt", "rt-multi-thread"] }
actix-files = "0.3"


~553K SLoC