Floor – Web development with Rust
cburgdorf.github.io
cburgdorf.github.io
server.smelt(JSON::new());
At least they're consistently hip!Iron looks smart and I might steal some ideas or code along the way. I come in peace :)
request.params.get(&"userid".to_string()).as_slice()
is rather ugly in comparison with Express's `req.params.userid` (or Sinatra's `params[:userid]`). Can something nicer be done here?I created a ticket to check all usage of Strings in the entire code base. You might want to track it for further progress on that.
Edit:
I don't think it does let you serve HTTPS requests:
https://github.com/cburgdorf/Floor/blob/548916fe7e4cbdc67eed...
One could SSL terminate with nginx though, but the problem of easy SSL in Rust persists.
Eventually rust-http (or rather, Teepee) will be capable of doing all these things itself, but for the moment—be cautious. For that matter, I don’t recommend that people write web things in Rust yet.
That said, I'm still learning the basics of Rust and therefore try to narrow the scope. Floor strives for simplicity rather than being feature rich. When I turned to Rust I was disappointed to see what the state of web development was. It seemed to be extremely complicated to even write a very simple web server. Especially compared to how easy such things are with something like express.js.
Rust is still under heavy development but I think we will see a lot of those missing bits popping out here and there in the coming months.
http://cburgdorf.github.io/Floor/doc/floor/struct.Floor.html...
pub struct Request<''a> {
pub origin: &''a Request,
pub params: HashMap<String, String>,
}Its true form is
pub struct Request<'a> {
pub origin: &'a Request,
pub params: HashMap<String, String>
}
where the 'a is representing the lifetime of the origin reference (that is, it is asserting that a Request struct is only usable for as long as the reference in the `origin` field is valid). Lifetimes/references are one of the core features of Rust guaranteeing both memory safety and performance.See also: http://doc.rust-lang.org/master/guide-lifetimes.html
https://github.com/cburgdorf/Floor/blob/master/src/request.r...
If you're unfamiliar, Rust has some fairly strict rules about lifetimes. Basically this syntax means that the thing referenced by `origin` needs to live for as long as the Request that contains it.
In rust "lifetime" can be a part of the type, so Rust compiler can ensure that no code can keep reference to `origin` for longer than it keeps reference to the structure that owns it.
What it means is the local request.Request object Floor passes to handlers takes an exclusive immutable borrow of the incoming http.Request object; the 'a is effectively just house keeping to make the compiler happy, because we know the http.Request, coming from a higher call will always exist for the lifetime of the request.Request object in the handler.
...so what you said is true, but the point is that we're asserting using prior knowledge that the compiler cant infer about the lifetime of that borrowed http.Request object.
At least, thats my take on it.