Compiling nickel v0.7.0 (file:///Users/matt/Documents/Projects/nickel.rs)
examples/chaining2.rs:9:5: 9:11 error: `server` does not live long enough
examples/chaining2.rs:9 server
^~~~~~
note: reference must be valid for the static lifetime...
examples/chaining2.rs:8:36: 18:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 8:35
examples/chaining2.rs: 8 let mut server = Nickel::new();
examples/chaining2.rs: 9 server
examples/chaining2.rs:10 .route("/")
examples/chaining2.rs:11 .get(middleware!("get"))
examples/chaining2.rs:12 .post(middleware!("post"))
examples/chaining2.rs:13 .put(middleware!("put"))
<header>
</header>
<body>
<h4>{{title}}</h4>
<ul>
{{#basket}}
<li>
<b>Name:</b> {{{name}}}
</li>
{{/basket}}
</ul>
</body>
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.