Generic functions between mutability

Related: Make immutable mutable again - or make arrays of structures stack-allocated