Skip to content

Instantly share code, notes, and snippets.

@wycats

wycats/hello.rs

Last active Jan 3, 2016
Embed
What would you like to do?
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"]))
});
}
}
@halorgium

This comment has been minimized.

Copy link

@halorgium halorgium commented Jan 12, 2014

Is there a pattern of (or requirement for) using ; for functions which take an anonymous function?

@pzol

This comment has been minimized.

Copy link

@pzol pzol commented Jan 12, 2014

Looks a bit like sinatra. I like it!

@beakr

This comment has been minimized.

Copy link

@beakr beakr commented Jan 12, 2014

@pzol yes!

Looks a lot like a low-level C library for Sinatra

@wycats

This comment has been minimized.

Copy link
Owner Author

@wycats wycats commented Jan 12, 2014

@halorgium what do you mean?

@sutamatej

This comment has been minimized.

Copy link

@sutamatej sutamatej commented Jan 12, 2014

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

This comment has been minimized.

Copy link

@marcbowes marcbowes commented Jan 12, 2014

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

This comment has been minimized.

Copy link
Owner Author

@wycats 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
You can’t perform that action at this time.