Index
- Guessing Game
- Common Programming Concepts
- Understanding Ownership
- Using Structs
- Enums and Pattern Matching
- Managing Growing Projects with Packages, Crates, and Modules
- Defining Modules to Control Scope and Privacy
- Paths for Referring to an Item in the Module Tree
- Bringing Paths into Scope with the use Keyword
- Separating Modules into Different Files
- Common Collections
- Error Handling
- Generic Types, Traits, and Lifetimes
- Writing Automated Tests
- Object Oriented Programming
- Adding dependancies
- Option Take
- RefCell
- mem
- Data Structure
- Recipe
- Semi colon
- Calling rust from python
- Default
- Crytocurrency With rust
- Function chaining
- Question Mark Operator
- Tests with println
- lib and bin
- Append vector to hash map
- Random Number
- uuid4
- uwrap and option
- Blockchain with Rust
- Near Protocol
- Actix-web
Actix-web
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use listenfd::ListenFd;
struct AppState {
app_name: String,
}
async fn index(data: web::Data<AppState>) -> String {
let app_name = &data.app_name;
format!("Hello {}!", app_name)
}
async fn index2() -> impl Responder {
HttpResponse::Ok().body("Hello world again!")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let mut listenfd = ListenFd::from_env();
let mut server = HttpServer::new(|| {
App::new()
.data(AppState {
app_name: String::from("Actix-web"),
})
.service(
web::scope("/app")
.route("/", web::get().to(index))
.route("/again", web::get().to(index2)),
)
});
server = if let Some(listener) = listenfd.take_tcp_listener(0).unwrap() {
server.listen(listener)?
} else {
server.bind("127.0.0.1:8000")?
};
server.run().await
}
use listenfd::ListenFd;
struct AppState {
app_name: String,
}
async fn index(data: web::Data<AppState>) -> String {
let app_name = &data.app_name;
format!("Hello {}!", app_name)
}
async fn index2() -> impl Responder {
HttpResponse::Ok().body("Hello world again!")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let mut listenfd = ListenFd::from_env();
let mut server = HttpServer::new(|| {
App::new()
.data(AppState {
app_name: String::from("Actix-web"),
})
.service(
web::scope("/app")
.route("/", web::get().to(index))
.route("/again", web::get().to(index2)),
)
});
server = if let Some(listener) = listenfd.take_tcp_listener(0).unwrap() {
server.listen(listener)?
} else {
server.bind("127.0.0.1:8000")?
};
server.run().await
}
[dependencies]
actix-web = "2.0.0"
actix-rt = "1.1.1"
listenfd = "0.3.3"
systemfd --no-pid -s http::8000 -- cargo watch -x run