Last active
January 3, 2016 00:08
-
-
Save wycats/8380393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])) | |
}); | |
} | |
} |
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
No semicolon changes it from a statement to an expression. Leaving off the semicolon means you want to return the value of the expression.
The convention is to only use
return
of you want an early exit.