Looks like big_endian() returns a serializer borrowing from the config; if so, the config needs to be kept alive while the serializer is. In your first case, config() returns a config that’s going to be dropped on that line since it’s a temporary and not kept alive by anything.

The compiler doesn’t keep temps alive in constructs like this. Your ser is a &mut Serializer, which as mentioned means you’re borrowing the Serializer mutably from somewhere else. That somewhere else needs to be alive.

Rust does allow constructs like this though:

let v = &mut vec![1,2,3];

I’m not sure how it’s actually implemented in the compiler, but you can imagine a desugaring like: