mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
simplier examples
This commit is contained in:
parent
f0c346f18c
commit
e6feec62a8
@ -55,17 +55,9 @@ fn index(req: HttpRequest<AppState>) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sys = actix::System::new("example");
|
Application::build("/", AppState{counter: Cell::new(0)})
|
||||||
|
.resource("/", |r| r.handler(Method::GET, index)))
|
||||||
HttpServer::new(
|
.finish();
|
||||||
Application::build("/", AppState{counter: Cell::new(0)})
|
|
||||||
.resource("/", |r| r.handler(Method::GET, index)))
|
|
||||||
.serve::<_, ()>("127.0.0.1:8088").unwrap();
|
|
||||||
|
|
||||||
println!("Started http server: 127.0.0.1:8088");
|
|
||||||
actix::Arbiter::system().send(actix::msgs::SystemExit(0)); // <- remove this line, this code stops system during testing
|
|
||||||
|
|
||||||
let _ = sys.run();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -164,11 +156,6 @@ fn main() {
|
|||||||
If `specialization` is enabled, conversion could be simplier:
|
If `specialization` is enabled, conversion could be simplier:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
#[derive(Serialize)]
|
|
||||||
struct MyObj {
|
|
||||||
name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Result<HttpResponse>> for MyObj {
|
impl Into<Result<HttpResponse>> for MyObj {
|
||||||
fn into(self) -> Result<HttpResponse> {
|
fn into(self) -> Result<HttpResponse> {
|
||||||
let body = serde_json::to_string(&self)?;
|
let body = serde_json::to_string(&self)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user