Rust

Make for Project on Rust with Docker


build:
	@cargo build

clean:
	@cargo clean

TESTS = ""
test:
	@cargo test $(TESTS) --offline -- --color=always --test-threads=1 --nocapture

mongostart:
	@sudo docker run -d -p 27017:27017 -v `pwd`/data/db:/data/db --name bookydb mongo

mongostop:
	@sudo docker stop bookydb && sudo docker rm bookydb

docs: build
	@cargo doc --no-deps

style-check:
	@rustup component add rustfmt 2> /dev/null
	cargo fmt --all -- --check

lint:
	@rustup component add clippy 2> /dev/null
	touch src/**
	cargo clippy --all-targets --all-features -- -D warnings

dev:
	@cargo run

.PHONY: build test docs style-check lint

Actix Web Server


use actix_web::{App, Error, HttpResponse, HttpServer, web};
use actix_web::http::{StatusCode};

async fn home() -> Result {
    Ok (
        HttpResponse::build(StatusCode::OK)
            .content_type("text/html; charset=utf-8")
            .body(include_str!("../templates/index.html"))
    )
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(move || {
        App::new()
            .route("/", web::get().to(home))
    })
    .bind("127.0.0.1:8888")?
    .run()
    .await
}