Skip to content

Instantly share code, notes, and snippets.

@wycats
Last active January 3, 2016 00:08
Show Gist options
  • Save wycats/8380393 to your computer and use it in GitHub Desktop.
Save wycats/8380393 to your computer and use it in GitHub Desktop.
fn main() {
do RoutedServer::serve |config, router| {
config.listen("127.0.0.1", 1337);
router.get("/hello", |_,res| res.write("hello world"));
router.get("/posts/:id", |req,res| {
res.write(format!("post {}", req.params["id"]))
});
}
}
@wycats
Copy link
Author

wycats commented Jan 12, 2014

@halorgium what do you mean?

@sutamatej
Copy link

I think he's just confused by (inconsistent?) rules for semicolon usage, i.e. no trailing semicolon on lines 3 & 8, but there is one on lines 5 & 9.

@marcbowes
Copy link

No semicolon changes it from a statement to an expression. Leaving off the semicolon means you want to return the value of the expression.

"foo"
return "foo";

The convention is to only use return of you want an early exit.

@wycats
Copy link
Author

wycats commented Jan 12, 2014

Line 3 was a bug. Line 8 probably should have a semicolon but write() returns () so it doesn't matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment