RUST_BACKTRACE=1
before your command, e.g. RUST_BACKTRACE=1 cargo test
function (err, res) {...}
and rust operations should return a result type that you can match against. match res {
Ok(v) => // do something with v,
Err(err) => // handler err
}
try_with!
, as seen in an old example here: https://github.com/Ryman/nickel-todo-backend/blob/master/src/main.rs#L77
nickel-sqlite
and nickel-postgres
will panic due to unwraps, which should 500
but doesn't (see hyperium/hyper#676 as a proposed fix for handling panics better in hyper). You can implement this behavior yourself with a frontloaded Middleware which sets the default StatusCode to 500
or whatever you need, and that will be used if things panic.
NickelError
here: http://docs.nickel.rs/nickel/struct.NickelError.html. The examples show how to register custom handlers for different error codes: https://github.com/nickel-org/nickel.rs/blob/master/examples/example.rs#L127. Is that what you wanted to do?
String
/&str
, you generally want to use &str
, simply because you can create a &str
cheaply from a String
, but not the other way around.
mount
middleware. See the actual implementation here.
mount
? I only meant for you to look at it as an example of how to run some code before a middleware is reached. You probably want some other logic, where you send users to different pages depending on whether they're logged in or not, no?
fn a(foo: &str) -> &str
, and in this function you want to call a function fn b(bar: String) -> String
with foo
as the parameter. In this case you will have to write foo.to_owned()
which will have to copy every character to create a String
, which is undesirable for performance reason. That is why we never actually take String
as a parameter unless we really need an owned string.