Why can’t I use a key function that returns a reference when sorting a vector with sort_by_key?

For now, you have to use the “long” form: v.sort_by(|x, y| key(x).cmp(&key(y))); Why am I getting these errors? Is there any way to fix them? The cause and fix are one-and-the same: Rust is simply not currently expressive enough to represent what you want. The feature needed is called generic associated types (GATs); previously known … Read more

How to set lifetime of session

The sessions on PHP works with a Cookie type session, while on server-side the session information is constantly deleted. For set the time life in php, you can use the function session_set_cookie_params, before the session_start: session_set_cookie_params(3600,”/”); session_start(); For ex, 3600 seconds is one hour, for 2 hours 3600*2 = 7200. But it is session cookie, … Read more

“borrowed value does not live long enough” when using the builder pattern

Here’s a minimal reproduction: #[derive(Debug)] pub struct Canvas; impl Canvas { fn new() -> Self { Canvas } fn color(&self) -> &Canvas { self } } fn main() { let mut canvas = Canvas::new().color(); // 1 ^~~~~~~~~~~~~ // 2 ^~~~~ println!(“{:?}”, canvas); } Rust 2015 error[E0597]: borrowed value does not live long enough –> src/main.rs:15:22 … Read more