iron / iron/iron.github.io

Document how to extend server lifetime.

Open
#27 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
4
Forks
10
PR merge metrics
No merged PRs in 30d

Description

The example on the front page never prints "On 3000" because the lifetime of the `Listening` returned from `http().unwrap()` expires within its own statement and then blocks the program. The solution to this is to store this value in an unused variable so that its lifetime is extended until the end of the block.

For example:

``` rust
let _listener = Iron::new(hello_world).http("localhost:3000").unwrap();
```

The leading `_` suppresses unused variable warnings (but note that it cannot just be called `_` since that has no lifetime).

It would also be good to add a note to the `Iron.http` and `Iron.https` methods where they discuss the guard to explain how to prevent it blocking.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.